32 MinimumVariableNameLength(Options.get(
"MinimumVariableNameLength",
34 MinimumLoopCounterNameLength(Options.get(
36 MinimumExceptionNameLength(Options.get(
38 MinimumParameterNameLength(Options.get(
40 IgnoredVariableNamesInput(
42 IgnoredVariableNames(IgnoredVariableNamesInput),
43 IgnoredLoopCounterNamesInput(Options.get(
"IgnoredLoopCounterNames",
45 IgnoredLoopCounterNames(IgnoredLoopCounterNamesInput),
46 IgnoredExceptionVariableNamesInput(
47 Options.get(
"IgnoredExceptionVariableNames",
49 IgnoredExceptionVariableNames(IgnoredExceptionVariableNamesInput),
50 IgnoredParameterNamesInput(
52 IgnoredParameterNames(IgnoredParameterNamesInput) {}
55 Options.store(Opts,
"MinimumVariableNameLength", MinimumVariableNameLength);
56 Options.store(Opts,
"MinimumLoopCounterNameLength",
57 MinimumLoopCounterNameLength);
58 Options.store(Opts,
"MinimumExceptionNameLength", MinimumExceptionNameLength);
59 Options.store(Opts,
"MinimumParameterNameLength", MinimumParameterNameLength);
60 Options.store(Opts,
"IgnoredLoopCounterNames", IgnoredLoopCounterNamesInput);
61 Options.store(Opts,
"IgnoredVariableNames", IgnoredVariableNamesInput);
62 Options.store(Opts,
"IgnoredExceptionVariableNames",
63 IgnoredExceptionVariableNamesInput);
64 Options.store(Opts,
"IgnoredParameterNames", IgnoredParameterNamesInput);
68 if (MinimumLoopCounterNameLength > 1)
70 forStmt(hasLoopInit(declStmt(forEach(varDecl().bind(
"loopVar"))))),
73 if (MinimumExceptionNameLength > 1)
74 Finder->addMatcher(varDecl(hasParent(cxxCatchStmt())).bind(
"exceptionVar"),
77 if (MinimumParameterNameLength > 1)
78 Finder->addMatcher(parmVarDecl().bind(
"paramVar"),
this);
80 if (MinimumVariableNameLength > 1)
82 varDecl(unless(anyOf(hasParent(declStmt(hasParent(forStmt()))),
83 hasParent(cxxCatchStmt()), parmVarDecl())))
84 .bind(
"standaloneVar"),
89 const auto *StandaloneVar = Result.Nodes.getNodeAs<VarDecl>(
"standaloneVar");
91 if (!StandaloneVar->getIdentifier())
94 StringRef VarName = StandaloneVar->getName();
96 if (VarName.size() >= MinimumVariableNameLength ||
97 IgnoredVariableNames.match(VarName))
101 << 0 << StandaloneVar << MinimumVariableNameLength;
104 auto *ExceptionVarName = Result.Nodes.getNodeAs<VarDecl>(
"exceptionVar");
105 if (ExceptionVarName) {
106 if (!ExceptionVarName->getIdentifier())
109 StringRef VarName = ExceptionVarName->getName();
110 if (VarName.size() >= MinimumExceptionNameLength ||
111 IgnoredExceptionVariableNames.match(VarName))
115 << 1 << ExceptionVarName << MinimumExceptionNameLength;
118 const auto *LoopVar = Result.Nodes.getNodeAs<VarDecl>(
"loopVar");
120 if (!LoopVar->getIdentifier())
123 StringRef VarName = LoopVar->getName();
125 if (VarName.size() >= MinimumLoopCounterNameLength ||
126 IgnoredLoopCounterNames.match(VarName))
130 << 2 << LoopVar << MinimumLoopCounterNameLength;
133 const auto *ParamVar = Result.Nodes.getNodeAs<VarDecl>(
"paramVar");
135 if (!ParamVar->getIdentifier())
138 StringRef VarName = ParamVar->getName();
140 if (VarName.size() >= MinimumParameterNameLength ||
141 IgnoredParameterNames.match(VarName))
145 << 3 << ParamVar << MinimumParameterNameLength;
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.