Clang Tidy 配置格式

Clang Tidy config format

目前我正在我的项目中使用 Clang 格式实用程序。为了在我的团队中共享它的设置,我将 .clang-format 配置文件放在项目文件夹的根目录下,现在 IDE 在使用项目时自动加载它。 同样,我想使用 Clang Tidy 实用程序。但是,与 Clang 格式不同,我找不到配置文件格式的描述或创建它的实用程序。我还需要 IDE 来自动加载这些设置并在自动格式化时将它们考虑在内,所以我不可能 运行 使用将向其传递必要参数的脚本的实用程序。有什么办法可以达到我的要求吗?

.clang-tidy文件格式其实是在命令行帮助中指定的,见the documentation.

--config=<string>              -
                                   Specifies a configuration in YAML/JSON format:
                                     -config="{Checks: '*',
                                               CheckOptions: [{key: x,
                                                               value: y}]}"
                                   When the value is empty, clang-tidy will
                                   attempt to find a file named .clang-tidy for
                                   each source file in its parent directories.
  --config-file=<string>         -
                                  Specify the path of .clang-tidy or custom config file:
                                    e.g. --config-file=/some/path/myTidyConfigFile
                                  This option internally works exactly the same way as
                                    --config option after reading specified config file.
                                  Use either --config-file or --config, not both.

您需要做的就是将配置字符串放入文件中,然后就可以开始了。如果您不指定 --config-file 选项,它将自动在检查代码所在的目录中搜索 .clang-tidy 文件。

示例 .clang-tidy 文件:

Checks: '-*,bugprone-*'
CheckOptions:
    - key: bugprone-argument-comment.StrictMode
      value: 1
    - key: bugprone-exception-escape.FunctionsThatShouldNotThrow
      value: WinMain,SDL_main
FormatStyle: 'file'

这将 运行 所有容易出错的检查并为其中两个设置选项。