jbenden / vscode-c-cpp-flylint

A VS Code extension for advanced, modern, static analysis of C/C++ that supports a number of back-end analyzer programs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for CppCheck `--project` option

Zelnes opened this issue · comments

Hello,

When using the extension with cppcheck with it's --project=/path/to/compile_commands.json, the extension fails to exclude one of the output from cppcheck.
A sample output is :

Checking /path/src/file1.c ...
Checking /path/src/file1.c: __DEBUG__=1...
1/9 files checked 11% done
Checking /path/src/file2.c ...
Checking /path/src/file2.c: __DEBUG__=1...
2/9 files checked 22% done
Checking /path/src/file3.c ...
Checking /path/src/file3.c: __DEBUG__=1...
3/9 files checked 33% done

And so on, up to 9/9.

I'm not yet familiar wirt extensions in VScode (I pulled the repo, changed in server/src/linters/cppcheck.ts, but was unable to make it work, even without the change), but I changed the server/out/server.js and it did work after that.

Here is the diff

diff --git a/server/src/linters/cppcheck.ts b/server/src/linters/cppcheck.ts
index aad30ad..0eebff5 100644
--- a/server/src/linters/cppcheck.ts
+++ b/server/src/linters/cppcheck.ts

@@ -74,7 +74,7 @@ export class CppCheck extends Linter {
         let regex = /^(.+?)\s\s([0-9]+)\s([0-9]+\s)?\s(style|information|portability|performance|warning|error)\s(.+?):\s(.*)$/;
         let regexArray: RegExpExecArray | null;
 
-        let excludeRegex = /^((Checking |Defines:|Undefines:|Includes:|Platform:|.*information missingInclude.*).*|cppcheck: .*. Disabling .* check.|)$/;
+        let excludeRegex = /^((Checking |Defines:|Undefines:|Includes:|Platform:|.*information missingInclude.*|.*files checked.*).*|cppcheck: .*. Disabling .* check.|)$/;
 
         if (excludeRegex.exec(line) !== null) {
             // skip this line

Well, it fits my need as of now, but would be appreciated to have it by default :D (or maybe I missed an option ?)

Thank you for this extension anyway, it's very nice

It seems that cppcheck outputs info on stdout and real messages (that matches the template) on stderr.
In the logs we can actually see 2 sets/arrays of strings parsed.
May be dealing only with the stderr could simplify the process ? And avoid regex computation time (I have 1K or more files that are processed by cppcheck, it could help)

Last thing, the verbose mode is possible in the extension, but actually not supported.
When I set it, I have this output :

/path/src/file1.c  110  style variableScope: The scope of the variable 'foo' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
    int i = 0;
    if (x) {
        // it's safe to move 'int i = 0;' here
        for (int n = 0; n < 10; ++n) {
            // it is possible but not safe to move 'int i = 0;' here
            do_something(&i);
        }
    }
}

And this gives multiple lines to treat by the extension, which make it goes in error.

I'm running into this issue, too. I can't modify the files locally, will there be a fix in the future?

Thanks!