Clang-tidy has had an on growing issue with blindly adding all checks from a module using the -checks=somemodule-* option. If somemodule alias' another enabled check. the check will get ran twice giving duplicated warning and fix options. This can lead to fixes overlapping preventing them from being applied or worse still applying twice resulting in malformed code. There are other issues with ConfigOptions being different in the 2 different instances so one instance of the check may be running a different set of options to the other.
This patch solves these issue by making clang-tidy only run 1 instance of an aliased check even if it has been turned on with multiple names. Warning messages are appended with the original check name if it has been enabled(via cmd line, or config file). If the original check hasn't been enabled then the name will be the first enabled alias that was registered.
Config options are also handled in a similar fashion, see example
[{ key: MyAliasedName.Option1, value: 0 }. { key: OriginalCheckName.Option1, value: 1 }]
If the check original-check-name was turned on, then Option1 will be parsed as being 1, otherwise it ignores OriginalCheckName.Option1 key and falls back to the first enabled alias check that declares Option1
To declare a check as an alias when you register then check, just add the check this alias' to as a second parameter
CheckFactories.registerCheck<readability::BracesAroundStatementsCheck>( "hicpp-braces-around-statements"); // Update to CheckFactories.registerCheck<readability::BracesAroundStatementsCheck>( "hicpp-braces-around-statements", "readability-braces-around-statements");
I haven't added in all the alias declarations in just yet (If you want me to just ask), nor have I added test cases. However once all the alias declarations are added in, the tests fall nicely in line with the current test infrastructure.
Adding this line to the readability-braces-around-statements checks causes no errors, no multiple fix attempts or warning messages.
// RUN: %check_clang_tidy %s readability-braces-around-statements,hicpp-readability-braces-around-statements %t
Likewise changing it to
// RUN: %check_clang_tidy %s hicpp-readability-braces-around-statements %t
Also runs without a hitch (obviously warning messages are appended with [hicpp-readability-braces-around-statements] instead of [readability-braces-around-statements] as above.
clang-tidy: warning: invalid case style for function 'alias_begin' [readability-identifier-naming]