[PATCH] D97753: [clang-tidy] Add a check for enforcing minimum length for variable names

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 11 07:39:02 PDT 2021


aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from some style nits (removing some top-level `const` we don't typically use, unnecessary paren expressions, and a typo fix), thank you for the check!



================
Comment at: clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp:99
+
+    const StringRef VarName = StandaloneVar->getName();
+
----------------



================
Comment at: clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp:101
+
+    if ((VarName.size() >= MinimumVariableNameLength) ||
+        IgnoredVariableNames.match(VarName))
----------------



================
Comment at: clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp:115-116
+
+    const StringRef VarName = ExceptionVarName->getName();
+    if ((VarName.size() >= MinimumExceptionNameLength) ||
+        IgnoredExceptionVariableNames.match(VarName))
----------------



================
Comment at: clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp:129
+
+    const StringRef VarName = LoopVar->getName();
+
----------------



================
Comment at: clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp:144
+
+    const StringRef VarName = ParamVar->getName();
+
----------------



================
Comment at: clang-tools-extra/docs/clang-tidy/checks/readability-identifier-length.rst:81
+    The default value is `^[ijk_]$`; the first three symbols for historical
+    reasons and the last one since it is frequently used as a "dont't care"
+    value, specifically in tools such as Google Benchmark.
----------------



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97753/new/

https://reviews.llvm.org/D97753



More information about the cfe-commits mailing list