[clang-tools-extra] [clang-tidy][readability-identifier-length] refactoring and cleanup (PR #194610)

Alex Dutka via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 29 02:47:27 PDT 2026


================
@@ -138,99 +138,61 @@ static bool isShortLived(const ValueDecl *Var, const SourceManager *SrcMgr,
 }
 
 void IdentifierLengthCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *StandaloneVar =
-      Result.Nodes.getNodeAs<ValueDecl>("standaloneVar");
-  if (StandaloneVar) {
-    if (!StandaloneVar->getIdentifier())
-      return;
+  auto ShouldWarn = [&](const ValueDecl *Var, unsigned MinNameLength,
+                        const llvm::Regex &IgnoredNames) -> bool {
+    if (!Var->getIdentifier())
+      return false;
 
-    const StringRef VarName = StandaloneVar->getName();
+    const StringRef VarName = Var->getName();
+    if (VarName.size() >= MinNameLength || IgnoredNames.match(VarName))
+      return false;
 
-    if (VarName.size() >= MinimumVariableNameLength ||
-        IgnoredVariableNames.match(VarName))
-      return;
-
-    if (isShortLived(StandaloneVar, Result.SourceManager, Result.Context,
+    if (isShortLived(Var, Result.SourceManager, Result.Context,
                      LineCountThreshold))
-      return;
+      return false;
 
-    diag(StandaloneVar->getLocation(), ErrorMessage)
-        << 0 << StandaloneVar << MinimumVariableNameLength;
+    return true;
+  };
+
+  if (const auto *StandaloneVar =
+          Result.Nodes.getNodeAs<ValueDecl>("standaloneVar")) {
+    if (ShouldWarn(StandaloneVar, MinimumVariableNameLength,
+                   IgnoredVariableNames))
+      diag(StandaloneVar->getLocation(), ErrorMessage)
+          << 0 << StandaloneVar << MinimumVariableNameLength;
----------------
dutkalex wrote:

Done

https://github.com/llvm/llvm-project/pull/194610


More information about the cfe-commits mailing list