| #
f9974f7f |
| 18-Nov-2023 |
J.C. Moyer <jcmoyer32@gmail.com> |
[clang-tidy] Improve alternate snake case warnings (#71385)
Improves the accuracy of `readability-identifier-naming` for cases
`Camel_Snake_Case` and `camel_Snake_Back`. Prior to this commit, these
[clang-tidy] Improve alternate snake case warnings (#71385)
Improves the accuracy of `readability-identifier-naming` for cases
`Camel_Snake_Case` and `camel_Snake_Back`. Prior to this commit, these
cases matched identifiers with **only** a leading upper case letter or
leading lower case letter respectively. Now, uppercase letters can only
appear at the start of an identifier or directly following an
underscore.
---
Currently, the regex for `Camel_Snake_Case` matches any identifier that
starts with a capital letter:
```
^[A-Z]([a-z0-9]*(_[A-Z])?)*
^^^^^^^^^-- underscore + capital letter after the first capital is optional
```
This means that `Camel_Snake_Case` matches other cases - in particular
`CamelCase` and `Leading_upper_snake_case` - which causes clang-tidy to
sometimes not flag incorrect casing. It also matches `UPPER_CASE`, but I
think it's reasonable to consider this a subset of `Camel_Snake_Case`
since some users may prefer e.g. `XML_Parser` to `Xml_Parser`. It's
really easy to accidentally type an identifier that clang-tidy doesn't
catch; all you have to do is omit an underscore or forget to capitalize
a letter. The same problem also applies to `camel_Snake_Back` except
that any identifier starting with a lower case letter matches, so I went
ahead and adjusted its regex too. Fixing it also uncovered a minor error
in an existing test.
show more ...
|