Page MenuHomePhabricator

[clangd] Cleanup of readability-identifier-naming

Authored by kuhnel on Dec 13 2021, 6:49 AM.



Auto-generated patch based on clang-tidy readability-identifier-naming.
Only some manual cleanup for extern "C" declarations and a GTest change was required.

I'm not sure if this cleanup is actually very useful. It cleans up clang-tidy findings to the number of warnings from clang-tidy should be lower. Since it was easy to do and required only little cleanup I thought I'd upload it for discussion.

One pattern that keeps recurring: Test matchers are also supposed to start with a lowercase letter as per LLVM convention. However GTest naming convention for matchers start with upper case. I would propose to keep stay consistent with the GTest convention there. However that would imply a lot of //NOLINT throughout these files.

To re-product this patch run:

run-clang-tidy -checks="-*,readability-identifier-naming" -fix -format ./clang-tools-extra/clangd

To convert the macro names, I was using this script with some manual cleanup afterwards:

Diff Detail

Event Timeline

kuhnel created this revision.Dec 13 2021, 6:49 AM
kuhnel requested review of this revision.Dec 13 2021, 6:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2021, 6:49 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
kuhnel edited the summary of this revision. (Show Details)Dec 13 2021, 7:06 AM
kuhnel added subscribers: sammccall, hokein.
kuhnel retitled this revision from Cleanup of readability-identifier-naming to [clangd] Cleanup of readability-identifier-naming.Dec 13 2021, 7:38 AM

Generally looks good with a few nits for individual names.

The matcher cleanup is a problem though, because you haven't cleaned up the functions created using the macros MATCHER, MATCHER_P, MATCHER_P2 etc. Presumably this is because names created through macros are excluded by the clang-tidy check.
IMO as a question of style we need to change all such functions we define or none of them.


I don't think it makes sense to keep the K here if it has to be uppercase.

The LLVM styleguide doesn't encourage this prefix. Styleguides that do tend to use a lowercase k for readability. If we want to strictly follow the LLVM styleguide I think we should just drop it.

15 ↗(On Diff #393876)

We use IO rather than Io for initialisms.
There are cases where the type/name can't match, but this doesn't appear to be one of them (we use IO &IO in similar mapping function below)


Note that MATCHER_P(FileURI, F, "") { ... ] above also defines a function returning a Matcher.

I think it's OK for our functions to have different case than matcher functions from the upstream gtest (different libraries have different styles), but I don't think it's OK for matcher functions to have different case depending on whether MATCHER_P was used or not.

And I agree that //NOLINT everywhere is not a good option.

So as far as I'm concerned:

  • OK: change these functions and also all the MATCHER, MATCHER_P etc instances to lowerCamelCase
  • OK: ignore this style rule and check results for matcher names
  • Not OK: follow the rule for explicitly-defined function but ignore it for MATCHER_Ps
  • Not OK: ignore the rule and add // NOLINT to enough exceptions to silence the checker
  • Bonus: teach the tidy check to flag violations introduced through macros (probably with an allowlist of macro names)

(I'm not quite sure how our convention of using UpperCamelCase for matcher factory functions got started, but I suspect it's from following upstream recipes without thinking hard about whether the new symbol is a function or a type).


this illustrates the problem: RefsAre({FileURI(...)}) or refsAre({fileURI}) make sense, but the mix does not.


This new name is no good, but in fact the variable is unused, just delete it


This name is also no good, and it's used exactly once - inline it


This is a magic function used by GTest, it is found via ADL and must be spelled exactly PrintTo.

This rename is dangerous because it doesn't cause tests to fail, but it causes them to have useless error messages if they fail later.

Please exclude this from the checker using the FunctionIgnoredRegexp.
Please make sure no other PrintTo functions have been renamed.

Discussion in team sync, work for myself:

  • most changes are in unittests --> propose something for the matchers
  • cleaning up constants makes sense
  • clean up this patch, then do another round of reviews
kuhnel updated this revision to Diff 403538.Jan 27 2022, 12:55 AM

Re-created the patch as there were too many changes in the repo.

Excluding gtest Matchers from naming checks as gtest convention does not match
LLVM convention.

kuhnel edited the summary of this revision. (Show Details)Jan 27 2022, 1:02 AM
kuhnel marked 6 inline comments as done.
kuhnel added inline comments.
15 ↗(On Diff #393876)

I tried a couple of variations of the config in the global .clang-tidy file, however none of them actually ignored the function:

  - key:             readability-identifier-naming.FunctionIgnoredRegexp
    value:           "LLVMFuzzerTest.*"

Any idea what I'm doing wrong?


My proposal here is to stick with the gtest naming convention for more consistency in the naming: Matchers start with upper case letters.

Thus I added //NOLINT to all matchers I encountered.

kuhnel updated this revision to Diff 403539.Jan 27 2022, 1:03 AM
kuhnel marked an inline comment as done.

addressed review comments

kuhnel marked an inline comment as done.Jan 27 2022, 1:04 AM
kuhnel edited the summary of this revision. (Show Details)Feb 1 2022, 4:18 AM
kuhnel updated this revision to Diff 404881.Feb 1 2022, 4:20 AM
kuhnel edited the summary of this revision. (Show Details)

re-created patch, then updated matcher macros

kuhnel updated this revision to Diff 404882.Feb 1 2022, 4:26 AM

fixed A_CC in BackgroundIndexTests.cpp

sammccall accepted this revision.Feb 1 2022, 5:03 AM

Thanks, this is great!
Just a few cases that regex couldn't quite understand, and one bona fide bug!


I think this got reverted - should just be FileBeingProcessed


this was a bug! should be VisitCoyieldExpr (capital because it's a CRTP override).

But this is is a functional bugfix, please either leave a fixme or change in a separate patch


This change also got lost (and in the next function)


id, not iD

This revision is now accepted and ready to land.Feb 1 2022, 5:03 AM
kuhnel marked 4 inline comments as done.Feb 1 2022, 5:31 AM

Thx @sammccall for your patience with this cleanup.


Right, sorry about the backsliding there. If I were ever to do such a cleanup again, I need to really split manual and automatic steps into separate commits and keep them in a separate branch before squashing them for arc diff.


added FIXME, feel feel free to create a patch for it

This revision was landed with ongoing or failed builds.Feb 1 2022, 5:32 AM
This revision was automatically updated to reflect the committed changes.
kuhnel marked an inline comment as done.