At the moment I am using the Clang Format utility in my project. In order to share its settings in my team, I put the .clang-format configuration file in the root of the project folder, and now IDE automatically loads it when working with the project. In the same way, I want to use the Clang Tidy utility. However, unlike Clang Format, I cannot find a description of the configuration file format or a utility to create it. I need IDE to also automatically load these settings and take them into account in autoformatting, so it's not possible for me to run the utility using a script that will pass it the necessary parameters. Is there a way to achieve what I need?
Asked
Active
Viewed 5,145 times
5
-
1I have got lost in the second part of the question, but you can generate config file with `clang-tidy --dump-config` call. Redirect/save it into `.clang-tidy` file in root of project. See https://clang.llvm.org/extra/clang-tidy/ – R2RT Nov 23 '21 at 13:44
-
I have a lot of custom parameters (for example - codestyle rules for "readability" section) and i didn't want to pass it all into commandline. But if it can create dump config, it will be okay to do this just one time. Thank you. – Timur Yalymov Nov 23 '21 at 13:53
1 Answers
7
.clang-tidy
file format is actually specified in the command-line help, see 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.
All you need to do is to put the config string in a file and you're good to go. If you don't specify the --config-file
option it will automatically search for a .clang-tidy
file in the directory where the checked code is.
An example .clang-tidy
file:
Checks: '-*,bugprone-*'
CheckOptions:
- key: bugprone-argument-comment.StrictMode
value: 1
- key: bugprone-exception-escape.FunctionsThatShouldNotThrow
value: WinMain,SDL_main
FormatStyle: 'file'
This would run all bugprone checks and set options for two of them.

pablo285
- 2,460
- 4
- 14
- 38