[all-commits] [llvm/llvm-project] f9974f: [clang-tidy] Improve alternate snake case warnings...

J.C. Moyer via All-commits all-commits at lists.llvm.org
Sat Nov 18 05:23:51 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f9974f7fe15a9e97ceb7514d437bef6ee46ccc38
      https://github.com/llvm/llvm-project/commit/f9974f7fe15a9e97ceb7514d437bef6ee46ccc38
  Author: J.C. Moyer <jcmoyer32 at gmail.com>
  Date:   2023-11-18 (Sat, 18 Nov 2023)

  Changed paths:
    M clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
    M clang-tools-extra/docs/ReleaseNotes.rst
    A clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
    M clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp

  Log Message:
  -----------
  [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.




More information about the All-commits mailing list