Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.3.0 (Unreleased)

- Fixed a bug where `latch` and `numbers` were not considered as c++ headers, courtesy of @GermanAizek. (https://github.com/matyalatte/cpplint-cpp/pull/6)
- `--exclude` now supports glob patterns. (https://github.com/matyalatte/cpplint-cpp/pull/9)
- Fixed a compile error on Ubuntu20.04 with an old version of GCC. (https://github.com/matyalatte/cpplint-cpp/pull/12)
- Added support for unix convention of using `-` for stdin. (https://github.com/matyalatte/cpplint-cpp/pull/13)

## 0.2.1 (2024-08-25)

- Initial release for cpplint-cpp.
32 changes: 16 additions & 16 deletions src/file_linter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4059,21 +4059,21 @@ void FileLinter::ProcessFile() {
std::vector<size_t> null_lines = {};
std::vector<std::string> lines = {};

if (StrIsChar(m_filename, '-')) {
// TODO(matyalatte): support stdin code
/*
lines = codecs.StreamReaderWriter(sys.stdin,
codecs.getreader('utf8'),
codecs.getwriter('utf8'),
'replace').read().split('\n');
*/
m_cpplint_state->PrintError("Skipping input \"-\": stdin is unsupported yet.\n");
return;
} else {
std::ifstream file(m_file, std::ios::binary);
if (!file) {
m_cpplint_state->PrintError(
"Skipping input '" + m_filename + "': Can't open for reading\n");
{
std::istream* stream;
std::ifstream file;
if (StrIsChar(m_filename, '-')) {
// Read from stdin
stream = &std::cin;
} else {
// Read from a file
file = std::ifstream(m_file, std::ios::binary);
if (!file) {
m_cpplint_state->PrintError(
"Skipping input '" + m_filename + "': Can't open for reading\n");
return;
}
stream = &file;
}

// insert a comment line at the beginning of file.
Expand All @@ -4085,7 +4085,7 @@ void FileLinter::ProcessFile() {
buffer.resize(120);
// Note: We can't use getline cause it trims NUL bytes and a linefeed at EOF.
while ((status & LINE_EOF) == 0) {
std::string line = GetLine(file, &buffer, &status);
std::string line = GetLine(*stream, &buffer, &status);
if (!line.empty() && line.back() == '\r') {
// line ends with \r.
crlf_lines.push_back(linenum);
Expand Down
12 changes: 11 additions & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ std::vector<fs::path> Options::ParseArguments(int argc, char** argv,
std::vector<fs::path> filenames = {};
for (; argp < argv + argc; argp++) {
fs::path p = argp[0];
if (!fs::exists(p)) {
// Note: "-" is an alias for "read from stdin"
if (p != "-" && !fs::exists(p)) {
// TODO(unknown): Maybe make this have an exit code of 2 after all is done
cpplint_state->PrintError("Skipping input '" + p.string() + "': Path not found.");
continue;
Expand Down Expand Up @@ -504,6 +505,10 @@ void Options::ProcessIncludeOrderOption(const std::string& val) {

static bool ShouldBeExcluded(const fs::path& filename,
const std::vector<GlobPattern>& excludes) {
if (filename == "-") {
// "-" is an alias for "read from stdin"
return false;
}
std::string file_str = filename.string();
for (const GlobPattern& exc : excludes) {
// Check if file is the same as (or a child of) a glob pattern
Expand Down Expand Up @@ -545,6 +550,11 @@ std::vector<fs::path> Options::ExpandDirectories(const std::vector<fs::path>& fi
std::vector<fs::path> filtered = {};
std::set<std::string> extensions = GetAllExtensions();
for (const fs::path& f : filenames) {
if (f == "-") {
// "-" is an alias for "read from stdin"
filtered.emplace_back(f);
continue;
}
ExpandDirectoriesRec(f, filtered, extensions);
}
return filtered;
Expand Down