This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Extend CheckOptions to support grouping checks options
Needs RevisionPublic

Authored by njames93 on Apr 10 2023, 11:43 AM.

Details

Summary

Remove a lot of duplication in configuration files by supporting nested dictionaries in the CheckOptions entry

For Example to set ParameterCase, VariableCase and MemberCase in readability-identifier-naming this new syntax is supported

CheckOptions:
  readability-identifier-naming:
    ParameterCase: CamelCase
    VariableCase: camelBack
    MemberCase: UPPER_CASE

This maintains backwards compatability with the old method of input:

CheckOptions:
  readability-identifier-naming.ParameterCase: CamelCase

And:

CheckOptions:
  - key: readability-identifier-naming.ParameterCase
    value: CamelCase

This new syntax is also able to be interleaved with the current dictionary type input.

CheckOptions:
  readability-identifier-naming.ParameterCase: CamelCase
  readability-identifier-naming:
    VariableCase: camelBack
    MemberCase: UPPER_CASE

Typically the current dictionary syntax is meant for checks with only one configured option

The -dump-config option has been updated to use the grouped syntax for checks with more than one option(while also having a deterministic ordering)

Diff Detail

Event Timeline

njames93 created this revision.Apr 10 2023, 11:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 11:43 AM
njames93 requested review of this revision.Apr 10 2023, 11:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 11:43 AM
LegalizeAdulthood resigned from this revision.Apr 10 2023, 12:49 PM

There are so many ways of defining check configurations, and I never heard of them.
Maybe some separate section in documentation is needed for them.

There are so many ways of defining check configurations, and I never heard of them.
Maybe some separate section in documentation is needed for them.

The current documentation only defines this method

CheckOptions:
  <check_name.option_name>: <option_value>

It doesn't mention flow syntax {CheckOptions: {<check_name.option_name>: <option_value>, ...}} because thats implicit when using yaml.
The other syntax of using

CheckOptions:
  - key: <check_name.option_name>
    value: <option_value>
  - key: ...
    value: ...

And its Flow counterpart {CheckOptions: [{key: <check_option.option_name>, value: <option_value>}, {...} ]} were removed from the documentation as an old deprecated format, left for compatibility with old config files

carlosgalvezp requested changes to this revision.Jul 18 2023, 1:10 PM
carlosgalvezp added inline comments.
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
94–95

This function has become very large and hard to read. Would it be possible to split it into subfunctions so it's easier to follow? I think it would make sense to create 1 function per different format supported (I believe with this patch there's now 3 different formats supported).

This revision now requires changes to proceed.Jul 18 2023, 1:10 PM