How to use .clang-tidy config file?

Hi,

I would like to use .clang-tidy files instead of declaring all of my needs in the --config= switch (is this switch even supported? From what I can read in the docs (Redirecting...) it is not.)

Is there any way to accomplish this?

Using check_flags to pass the --config-file argument to clangtidy doesn’t work?

check_tool = clangtidy
check_flags =
  clangtidy: --config-file=.clang-tidy
1 Like

Hi, thank you for the idea. I tested it with no success. But is this command line argument even officially supported? I can’t find it in the docs, only in a thread from llvm.

Ok, today I have time to investigate this problem a little further. What I got so far: The binary version of clang-tidy.exe (resides in .platformio\packages\tool-clangtidy) is 12.0.1. The corresponding documentation can be found here: Clang-Tidy — Extra Clang Tools 12 documentation
There is nothing telling us about a config-file argument. But when I run
clang-tidy --help
it says that there is a possibility to use
--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.

But I am not yet able to use it.

The argument just seems not to be considered. When I run
pio check -v
I can see the actual command line call that is generated:
C:\Users\user\.platformio\packages\tool-clangtidy\clang-tidy --quiet --checks=* --config-file=C:/Users/user/Documents/PlatformIO/Projects/project/.clang-tidy
I tried several kinds of tpying the actual path to the config file (doublequotes, backslashes, …). Although there is a line in my clang-tidy file that looks like this
Checks: '-*'
the resulting command line arguments contain a
--checks=*
argument. Hm.

I ended up opening an issue: Enable "--config-file" flag for clang-tidy · Issue #4186 · platformio/platformio-core · GitHub