[clang-tools-extra] [clang-tidy][readability-identifier-length] Add a line count threshold (PR #185319)

via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 8 18:32:57 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.h clang-tools-extra/test/clang-tidy/checkers/readability/identifier-length.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp
index 4755588b7..af08ca342 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp
@@ -51,7 +51,8 @@ IdentifierLengthCheck::IdentifierLengthCheck(StringRef Name,
       IgnoredParameterNamesInput(
           Options.get("IgnoredParameterNames", DefaultIgnoredParameterNames)),
       IgnoredParameterNames(IgnoredParameterNamesInput),
-      LineCountThreshold(Options.get("LineCountThreshold", DefaultLineCountThreshold)) {}
+      LineCountThreshold(
+          Options.get("LineCountThreshold", DefaultLineCountThreshold)) {}
 
 void IdentifierLengthCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "MinimumVariableNameLength", MinimumVariableNameLength);
@@ -88,15 +89,17 @@ void IdentifierLengthCheck::registerMatchers(MatchFinder *Finder) {
         this);
 }
 
-static unsigned countLinesToLastUse(const VarDecl* Var, const SourceManager* SrcMgr, ASTContext* Ctx){
+static unsigned countLinesToLastUse(const VarDecl *Var,
+                                    const SourceManager *SrcMgr,
+                                    ASTContext *Ctx) {
   const unsigned DeclLine = SrcMgr->getSpellingLineNumber(Var->getLocation());
 
   class VarUseCallback : public MatchFinder::MatchCallback {
-   private:
-    unsigned* LastUseLineNumber;
+  private:
+    unsigned *LastUseLineNumber;
 
-   public:
-    explicit VarUseCallback(unsigned* Output): LastUseLineNumber{Output} {}
+  public:
+    explicit VarUseCallback(unsigned *Output) : LastUseLineNumber{Output} {}
 
     void run(const MatchFinder::MatchResult &Result) override {
       const DeclRefExpr *Use = Result.Nodes.getNodeAs<DeclRefExpr>("varUse");
@@ -132,7 +135,9 @@ void IdentifierLengthCheck::check(const MatchFinder::MatchResult &Result) {
         IgnoredVariableNames.match(VarName))
       return;
 
-    if (LineCountThreshold > 0 && countLinesToLastUse(StandaloneVar, Result.SourceManager, Result.Context) <= LineCountThreshold)
+    if (LineCountThreshold > 0 &&
+        countLinesToLastUse(StandaloneVar, Result.SourceManager,
+                            Result.Context) <= LineCountThreshold)
       return;
 
     diag(StandaloneVar->getLocation(), ErrorMessage)
@@ -149,7 +154,9 @@ void IdentifierLengthCheck::check(const MatchFinder::MatchResult &Result) {
         IgnoredExceptionVariableNames.match(VarName))
       return;
 
-    if (LineCountThreshold > 0 && countLinesToLastUse(ExceptionVarName, Result.SourceManager, Result.Context) <= LineCountThreshold)
+    if (LineCountThreshold > 0 &&
+        countLinesToLastUse(ExceptionVarName, Result.SourceManager,
+                            Result.Context) <= LineCountThreshold)
       return;
 
     diag(ExceptionVarName->getLocation(), ErrorMessage)
@@ -167,7 +174,9 @@ void IdentifierLengthCheck::check(const MatchFinder::MatchResult &Result) {
         IgnoredLoopCounterNames.match(VarName))
       return;
 
-    if (LineCountThreshold > 0 && countLinesToLastUse(LoopVar, Result.SourceManager, Result.Context) <= LineCountThreshold)
+    if (LineCountThreshold > 0 &&
+        countLinesToLastUse(LoopVar, Result.SourceManager, Result.Context) <=
+            LineCountThreshold)
       return;
 
     diag(LoopVar->getLocation(), ErrorMessage)
@@ -185,7 +194,9 @@ void IdentifierLengthCheck::check(const MatchFinder::MatchResult &Result) {
         IgnoredParameterNames.match(VarName))
       return;
 
-    if (LineCountThreshold > 0 && countLinesToLastUse(ParamVar, Result.SourceManager, Result.Context) <= LineCountThreshold)
+    if (LineCountThreshold > 0 &&
+        countLinesToLastUse(ParamVar, Result.SourceManager, Result.Context) <=
+            LineCountThreshold)
       return;
 
     diag(ParamVar->getLocation(), ErrorMessage)

``````````

</details>


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


More information about the cfe-commits mailing list