19

Right now I have a .clang-tidy file that includes a large list of checks and they all go in one line like this:

Checks: '-*,bugprone-*,-bugprone-narrowing-conversions, cert-*, -cert-err58-cpp, clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-narrowing-conversions...'

Is there a way to list each check (enabled or disabled) in multiple lines for easier version control?

Right now I toggle word wrap and that helps editing, but it's very hard to diff in code reviews.

I'm looking for something like this:

Checks:
'-*,'
'cert-*,etc-*,'
...
Darien Pardinas
  • 5,910
  • 1
  • 41
  • 48

2 Answers2

31

You can remove the single quotation marks and list all checks in a line-breaking comma separated list that starts with a > entry, constructing a .clang-tidy file as follows:

---
Checks: >
    -*,
    cert-*,
    etc-*,
    <additional checks ...>
...

As of D30567: [clang-tidy] Fix treating non-space whitespaces in checks list the leading whitespace on each new line are only for readability, and you may choose any consistent number of leading spaces (YAML).

dfrib
  • 70,367
  • 12
  • 127
  • 192
  • Actually, the file is a YAML, so leading whitespace is not the word. I used a tab to indent, and got an error (that's when I noticed this is a YAML). So "any consistent number of leading spaces" is more appropriate. – alx - recommends codidact May 12 '21 at 09:00
  • @alx Thanks for the ping! I've updated the answer. Feel free to propose an edit to the answer if you'd like it further updated. – dfrib May 12 '21 at 13:34
  • is there a way to add comments inbetween those lines? e.g. I want to describe why exactly particular check was enabled/disabled – artin Dec 20 '21 at 15:01
  • 1
    @dfrib no, it's not possible to do `#` _inbetween lines of multiline string_. that's why i see people [commenting each check completely outside the string](https://github.com/googleapis/google-cloud-cpp/blob/main/.clang-tidy) as a way around. I don't like it, it forces me to duplicate name of each check, but it the best way I've found so far. – artin Dec 20 '21 at 18:43
  • 1
    Really looks like clang-tidy's config format has been rushed out without much thought. It should clearly be defined as a sequence! Or were they afraid the minus symbol might make it confusing considering we may also have a minus before the check name to disable it ? – Johan Boulé Jan 10 '22 at 18:43
0

You can also use the back slash at the end of every line:

---
Checks: "-*,\
modernize-*,\
-modernize-use-trailing-return-type,\
misc-*,\
-misc-non-private-member-variables-in-classes,\
-misc-no-recursion,\
cppcoreguidelines-*,\
"
...
jaques-sam
  • 2,578
  • 1
  • 26
  • 24