.clang-tidy configuration file content is being ignored

Viewed 1465

I want to modify the checks that the code analyzer program clang-tidy is doing, but it seems like the content of the configuration file .clang-tidy is being ignored.

  1. I create the file by calling clang-tidy with the flag -dump-config and redirect the output to the file .clang-tidy.
  2. Then I call sed to replace the value 800 with the value 700, which corresponds to the option with key google-readability-function-size.StatementThreshold. The specific option is not important to me, this is just for testing.
  3. I verify that the value has indeed been changed.
  4. Lastly, I rerun clang-tidy to see if it has accepted the new configuration, but it remains unchanged.
# generate config
clang-tidy -dump-config > .clang-tidy
# change config
sed -i 's/800/700/' .clang-tidy
# verify change
grep '700' .clang-tidy
# use config, does not work
clang-tidy -config '' -dump-config

The CheckOption remains at the default value, the content of the config file has been ignored:

CheckOptions:
# some lines omitted for brevity
  - key:             google-readability-function-size.StatementThreshold
    value:           '800'

Running clang-tidy -config '' -dump-config -explain-config shows that the configuration file has at least been found, i.e. many clang-analyzer specific checks are enabled in the detected config file, but the check google-readability-function-size.StatementThreshold is not listed.

I also tried passing the config directly as command line parameter with the command clang-tidy -config="{CheckOptions: [ {key: google-readability-function-size.StatementThreshold, value: 700} ]}" -dump-config, but got the same result.

The command clang-tidy --version gives the following output, running on Ubuntu 20.04:

LLVM (http://llvm.org/):
  LLVM version 10.0.0
  
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: haswell
1 Answers

To see the change, you need to enable the check:

Checks:          'google-readability-function-size'

You can see it changed in the effective configuration with:

clang-tidy --dump-config

Another pitfall to be aware of is that errors parsing the values will be silently discarded.

Related