Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 805
Thomas Weller Avatar asked Dec 06 '25 15:12

Thomas Weller


1 Answers

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.
like image 87
Thomas Weller Avatar answered Dec 08 '25 11:12

Thomas Weller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!