Search code examples
c++visual-studioclang-tidy

How to enable and disable a clang-tidy rule in Visual Studio?


Visual Studio has a feature that lets me enable clang-tidy checks. In the property pages, I went to Configuration properties, Code analysis, General and set "Enable Clang-Tidy" to "Yes":

Enable Clang Tidy

In the Clang-Tidy section, Visual Studio allows me to enter Clang-Tidy rules:

Property pages

However, it says: "Enable or disable ...". How do I enable a check and how do I disable a check? That input box just takes a string.


Solution

  • The checks are passed to the clang-tidy command line as is. This means:

    1. You enable them by just using the string
    2. You disable them by adding a - in front of the check
    3. You separate multiple of them by comma
    4. You can use wildcards like clang-analyzer-*,-clang-analyzer-cplusplus*

    As mentioned on https://clang.llvm.org/extra/clang-tidy/:

    clang-tidy options:
    
    --checks=<string>       - Comma-separated list of globs with optional '-'
                              prefix. Globs are processed in order of
                              appearance in the list. Globs without '-'
                              prefix add checks with matching names to the
                              set, globs with the '-' prefix remove checks
                              with matching names from the set of enabled
                              checks. This option's value is appended to the
                              value of the 'Checks' option in .clang-tidy
                              file, if any.