cppcheck: error: unrecognized command line option: "--file-filter

cppcheck: error: unrecognized command line option: "--file-filter

我正在 Ubuntu 20.04 上开发 C 代码。

来自 运行 cppcheck -q --project=build/proj1/compile_commands.json --file-filter='src/base/Myfile.c'

我收到错误消息

cppcheck: error: unrecognized command line option: "--file-filter=src/base/Myfile.c".

看来Ubuntu20.04中包含的cppcheck版本不是最新的:

$ apt show cppcheck | grep Version
Version: 1.90-4build1

cppcheck 1.90 于 2019 年发布。--file-filter 参数在 2020 年提交 fcd5cda97 中引入:

$ git show fcd5cda97f10085c7def7fda6fc6199f624010ce
commit fcd5cda97f10085c7def7fda6fc6199f624010ce
Author: fuzzelhjb <chschmidt9@gmail.com>
Date:   Fri Jan 10 08:57:37 2020 +0100

    Check selected files from project (#2378)

diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp
index 3fbc7f6c6..292327051 100644
--- a/cli/cmdlineparser.cpp
+++ b/cli/cmdlineparser.cpp
@@ -376,6 +376,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
                 mSettings->xml = true;
             }

+            // use a file filter
+            else if (std::strncmp(argv[i], "--file-filter=", 14) == 0)
+                mSettings->fileFilter = std::string(argv[i] + 14);
+
             // Only print something when there are errors
             else if (std::strcmp(argv[i], "-q") == 0 || std::strcmp(argv[i], "--quiet") == 0)
                 mSettings->quiet = true;
@@ -1035,6 +1039,9 @@ void CmdLineParser::printHelp()
               "    --exitcode-suppressions=<file>\n"
               "                         Used when certain messages should be displayed but\n"
               "                         should not cause a non-zero exitcode.\n"
+              "    --file-filter=<str>  Analyze only those files matching the given filter str\n"
+              "                         Example: --file-filter=*bar.cpp analyzes only files\n"
+              "                                  that end with bar.cpp.\n"
               "    --file-list=<file>   Specify the files to check in a text file. Add one\n"
               "                         filename per line. When file is '-,' the file list will\n"
               "                         be read from standard input.\n"

cppcheck 的当前发行版本似乎是 2.7。