Page MenuHomePhabricator

Filter out messages from included files
ClosedPublic

Authored by svenax on Oct 30 2013, 12:52 PM.
Tags
None
Referenced Files
F13819053: D7444.id16812.diff
Fri, Sep 20, 11:45 AM
F13817484: D7444.id16813.diff
Fri, Sep 20, 12:19 AM
F13817483: D7444.id16812.diff
Fri, Sep 20, 12:19 AM
F13817482: D7444.id16772.diff
Fri, Sep 20, 12:19 AM
F13817481: D7444.id.diff
Fri, Sep 20, 12:19 AM
Unknown Object (File)
Fri, Sep 6, 10:25 PM
Unknown Object (File)
Wed, Aug 28, 5:04 PM
Unknown Object (File)
Sun, Aug 25, 9:58 AM

Details

Summary

CppCheck shows lint messages from included files as well as the current
file. Filter out those, since they don't make much sense in the context
of arc lint.

Test Plan

Before this patch, arc lint using ArcanistCppcheckLinter. Note that lint messages
from included files appear pointing to a line in the active file.
After this patch, only messages from the active file are included.

Diff Detail

Branch
filter-cppcheck-messages
Lint
Lint Passed
Unit
Tests Passed

Event Timeline

(See inline.)

src/lint/linter/ArcanistCppcheckLinter.php
118

Can we setPath($file) (or some approximation) here instead? Arcanist should be able to handle this correctly in the general case, and route/display the message properly, although obviously we're passing the wrong data right now.

$file might require canonicalization along these lines:

$root = $this->getEngine()->getWorkingCopy()->getProjectRoot();
$local_file = Filesystem::readablePath($file, $root);
// Maybe test if $local_file Filesystem::isDescendant() of $root, too?
// Not sure how far-reaching the messages are.

If there are reasons this isn't practical, the filtering fix seems reasonable to me, but this fix seems a little nicer if it does work.

src/lint/linter/ArcanistCppcheckLinter.php
118

I'm not familiar (yet) with the Arcanist source, but as far as I can see the simple filtering is what's needed. CppCheck now generates lints like this:

Checking src/ArticleType.cpp...
[src/Line.h:65]: (warning) Member variable 'Line::mNoWordBoxes' is not initialized in the constructor.
[src/Paragraph.h:37] -> [src/Paragraph.h:29]: (style, inconclusive) Member variable 'Paragraph::mText' is in the wrong place in the initializer list.
[src/TextFlow.h:42] -> [src/TextFlow.h:33]: (style, inconclusive) Member variable 'TextFlow::mLines' is in the wrong place in the initializer list.
[src/ContentType.h:68] -> [src/ContentType.h:45]: (style, inconclusive) Technically the member function 'ContentType::operatorint' can be const.

Where all the messages refer to other files than the one being linter. It seems to me that we don't need to do anything else than just filter them out.

Ah, okay -- these warnings aren't caused by changes to src/ArticleType.cpp, they just happen to be included in it? Elsewhere, we have some warnings like:

src/Thing.c:22 Function definition x() is broken...
src/Thing.h:19 Function declaration for broken x() is in header here...

In this case, raising the extra warning is desirable, because it's directly related to "Thing.c". It looks like these are just incidental, though. I agree that we should just filter them, in that case.

Oh, actually, one more thing -- by default, resolvePath() uses the CWD. I expect this patch won't work if you run it like this:

cd project/
cd blah/blah/blah/ # cd into somewhere deep in the project
arc lint ../../../src/ArticleType.cpp

Can you make sure that works? If it doesn't, $this->getEngine()->getWorkingCopy()->getProjectRoot(); should get the project root, and Filesystem::resolvePath($file, $root) should be comparable to $path or $this->getActivePath() (which should have the same value).

svenax updated this revision to Unknown Object (????).Oct 30 2013, 8:39 PM
  • Use $path instead of $this->getActivePath()

Yes, it works this way. Since the linter is called with $this->getEngine()->getFilePathOnDisk($path) which returns a full path, the value of $file will also always be a full path. I changed the patch to use $path instead of $this->getActivePath() to be more concise.

epriestley closed this revision.

Closed by commit rARCaabbdbd2ab95 (authored by @svenax, committed by @epriestley).