Search code examples
c++clangllvmclang-tidy

clang-tidy treats namespace as global variable when using readability-identifier-naming


I am using clang-tidy to lint source code. In the file .clang-tidy i defined:

Checks: '-*,readability-identifier-naming'
CheckOptions:
...
  - { key: readability-identifier-naming.NamespacePrefix,               value: n1_        },
  - { key: readability-identifier-naming.GlobalVariablePrefix,          value: g1_        },
...

myHeader.h:

namespace n1_test
{
...
}

Linting this file with clang-tidy (tried 11.1.0, 13.0.0git(both compiled by myself) and 10.0.0(downloaded)) on Linux Mint 19.2 (Tina)

with:

clang-tidy-11.1.0 -export-fixes=fixes.txt /tmp/clangTest/mylib/source/myHeader.h -- -I/tmp/clangTest/myLib/source

results in:

 warning: invalid case style for global variable 'n1_test' [readability-identifier-naming]
namespace n1_test {
          ^~~~~~~~~~
          g1_n1_test

I don't understand why NamespacePrefix is not working and clang-tidy treats the namespace as a global variable. I also testest NamespaceCase and it isn't working to.

PS: According to the documentation this should work


Solution

  • can't use clang-tidy directly on header files. Instead i have to check the cpp file and have to add -header-filter=.* to also check the headers:

    clang-tidy-11.1.0 -header-filter=.* -export-fixes=fixes.txt /tmp/clangTest/mylib/source/main.cpp -- -I/tmp/clangTest/myLib/source