Repository navigation
Conversation
582af1e to
7f4334b
Compare
|
@claude review |
| // paths inside a matched directory are not traversed, so a pattern that is | ||
| // covered by a matched pattern is considered used | ||
| const Filemode mode = !s.empty() && PathIterator::issep(s.back(), mSyntax) ? Filemode::directory : Filemode::regular; | ||
| return std::none_of(mMatchedPatterns.cbegin(), mMatchedPatterns.cend(), [&](const std::string& matched) { |
There was a problem hiding this comment.
False negative: this "covered by a matched pattern" check runs against every matched pattern, but the reasoning only holds for patterns that matched a directory. Only directory matches stop the traversal. A file pattern never hides anything.
Examples where a stale pattern goes unreported:
-ifoo.cpp -inonexistent/foo.cpp:foo.cppmatcheslib/foo.cpp, andmatch("foo.cpp", "nonexistent/foo.cpp")is true, so the second pattern counts as used.-i*_test.cpp -imissing_test.cpp: the glob matches some file, somissing_test.cppis never reported.
Suggestion: keep track of which patterns matched with Filemode::directory, and only use those for this check.
|
|
||
| const auto& unmatched = matcher.unmatched(); | ||
| if (!unmatched.empty()) { | ||
| mLogger.printError("unused ignore/exclude path '" + unmatched.front() + "'. To hide warnings in certain files use suppressions instead."); |
There was a problem hiding this comment.
A couple of points about making this a hard error:
- Only
unmatched.front()is reported. If a user has several stale-ipaths, they have to fix one and re-run for each. Listing all of them would be easier to use (same for the project branch below). -ifoo.hnow always fails, because headers are never passed tomatch(). The user first sees the existing "filename exclusion does not apply to header files" info message and then this error. It may be worth making the two messages consistent.- Builds that share one ignore list across different path arguments will now fail. So will builds that ignore generated directories that don't exist yet, e.g.
-ibuild/on a fresh checkout. Is a hard error (rather than a warning) intended here? If so, the release note should call it out as a breaking change.
|
Overall the approach looks good:
🤖 Generated with Claude Code |
141c611 to
5e52f82
Compare
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
New false positive in PathMatch::unmatched(). An exclude pattern that matches files only inside a directory that another pattern already excludes is reported as unused, and the run stops with exit code 1. The "covered" check only compares the two pattern strings with each other (match("src/sub/", "b.c")). It never asks whether the second pattern would match something inside the skipped directory. So -ithird_party/ -i*.pb.cc . fails when all .pb.cc files are under third_party/. Ignore lists like this are common, and they worked before this PR. In my tests this was the only new problem.
Several earlier points are still in the code:
MainWindow::doAnalyzeProjectstill discards the result ofignorePaths(C2/C18).- The covered check still hides stale file/glob patterns (C11/C16).
- The GUI message is still a run-on sentence (C6).
- Only the first unused path is reported (C17).
Comments
18 comments, 6 open, 1 new
@danmar, please fix, resolve or reply to the open and new comments: #9, #12, #13, #15, #16, #17, #18.
For #9, #12, #16 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.
Testing
Builds
make -j8 cppcheck testrunnerinpr/built without errors.- I also built the GUI and its tests with CMake.
Unit and GUI tests
./testrunner TestPathMatch TestCmdlineParser TestFileLister TestImportProject: 466 tests, 0 failed.- GUI ctest (
test-filelistand the others): 5/5 passed.
Python tests in test/cli
- 585 passed and 16 failed.
- 12 of the failures are rule tests, because this build has no rules support ("Option --rule ...").
- The other 4 are
test_redundant_file_reads, which fails withFileNotFoundError, most likely a tool missing in the container. - I don't think any of these failures are related to the PR, but I did not run them against
base/.
Manual CLI tests (in /work/scratch/t1)
- These pass:
-isrc/sub/ src,-isub src,-i./src/sub/ src, absolute-i,-isrc/sub/ src/sub/b.c src/a.c, and-isrc/sub/ -i**/sub/ src.
Reproducer for the false positive
mkdir -p src/sub third_party/proto
echo "int a;" > src/a.c; echo "int b;" > src/sub/b.c; echo "int p;" > third_party/proto/x.pb.cc
$ cppcheck -q -isrc/sub/ -ib.c src
cppcheck: error: unused ignore/exclude path 'b.c'. To hide warnings in certain files use suppressions instead.
rc=1
$ cppcheck -q -isrc/sub/ -isub/b.c src
cppcheck: error: unused ignore/exclude path 'sub/b.c'. To hide warnings in certain files use suppressions instead.
rc=1
$ cppcheck -q -ithird_party/ -i*.pb.cc .
cppcheck: error: unused ignore/exclude path '*.pb.cc'. To hide warnings in certain files use suppressions instead.
rc=1
In each case the reported pattern does match an existing file (src/sub/b.c, third_party/proto/x.pb.cc). It is reported only because the directory is never traversed. Without this PR these command lines run normally.
Automated review of 0d886c7 by Claude. The pull request was built and tested locally.
| // paths inside a matched directory are not traversed, so a pattern that is | ||
| // covered by a matched pattern is considered used | ||
| const Filemode mode = !s.empty() && PathIterator::issep(s.back(), mSyntax) ? Filemode::directory : Filemode::regular; | ||
| return std::none_of(mMatchedPatterns.cbegin(), mMatchedPatterns.cend(), [&](const std::string& matched) { |
There was a problem hiding this comment.
AI review
The covered check only tests whether a matched pattern matches the text of the unmatched pattern. When a directory is excluded, files below it are never passed to match(). So a pattern that would only match files in there is reported as unused even though it does match existing files, unless its text happens to start with the directory's path. Examples that now fail with exit code 1:
$ cppcheck -isrc/sub/ -ib.c src # src/sub/b.c exists
cppcheck: error: unused ignore/exclude path 'b.c'. ...
$ cppcheck -isrc/sub/ -isub/b.c src
cppcheck: error: unused ignore/exclude path 'sub/b.c'. ...
$ cppcheck -ithird_party/ -i*.pb.cc . # all .pb.cc are below third_party/
cppcheck: error: unused ignore/exclude path '*.pb.cc'. ...
Ignore lists like -ithird_party/ -i*.pb.cc are common, and they worked before this PR. A comparison of pattern strings can't decide whether one pattern is "covered" by another. Two possible fixes:
- Keep walking the excluded directories (or at least record the paths below them) when you collect which patterns are used.
- Report an unmatched pattern only when it could not match anything in an excluded directory.
|
Test results for commit 0d886c7 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8906/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
Add the scenario "Unused exclude paths are reported" with the test project unused-exclude: one exclude path that matches a file and one that matches nothing. Only the unused path is reported. Regenerate the script of "Other Help menu entries" against a build that has online-help.qhc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No description provided.