Currently one can only specify checks as a string in the .clang-tidy file. This is unintuitive and comes with some drawbacks, as explained in this Github issue.
I have a proposal for a WIP patch to add support for specifying the Checks as either a string or a list of strings.
What do you think, does it sound reasonable? It’s my first time dealing with YAML in the project so I’m sure the code can be improved. I’m mostly interested in knowing if people support the idea in general. I also have some follow-up questions:
Should we deprecate the string format, and have it only as a list after a couple releases? That would greatly simplify the code.
What format should it use when outputting to YAML via --dump-config?
They are just workarounds, and as I wrote at the end, it’s not at all obvious that you are supposed to add a comma after the comment - otherwise clang-tidy will silently ignore the rest of the list, potentially removing active checks after the comment. Removing a check will go unnoticed in CI, so it can take a while before people realize what happened and then spend even more time figuring out how to solve it (the fact that a comma is needed is unintuitive and undocumented). By that time, a lot of technical debt has probably already creeped in such that is no longer possible to re-enable the checks.
We should not choose interfaces to match our backend - we should choose what makes sense and makes the tool user-friendly. To specify a list of things, the correct syntax in YAML is a list.
Anyhow we got this merged now:
The remaining question I had is if we should deprecate (remove it in clang-tidy X) the old syntax - supporting both is probably confusing to the user and adds complexity in our code. IMO if we always aim at backwards compatibility we will eventually end up in the same situation as C++: many ways of doing the same thing, a lot of technical debt accumulated that cannot be removed, and eventually people switching to other more modern and expressive alternatives.
Is there a yaml specification that clarifies the use of a comment in this location?
I don’t think so.
I don’t see the burden of having the comment at the top as we do.
The rationale is the same as why one should have variables in code as close as possible to where they are used: locality of reference. In your example, if one day you remove a check, you will most likely forget to remove the comment at the very top that explains something about the check. In our case, we have plenty of comments documenting why certain checks are disabled, links to bugs, etc. It becomes very hard to read to have all that information at the very top.
If we take a step back to the basics I think it’s a simple reasoning. This is a list of checks. YAML supports lists natively. Therefore a YAML list should be the first and most intuitive choice to specify checks. Why should things be more complicated than they need to be?
There’s more issues, for example users need to spend time reading about how to do multi-line strings in YAML, learn about > versus |, reason about newlines or spaces, etc. Really a lot of effort just to declare a list.
Could you provide a motivation as to why a string is better than a list to represent a list?