changed rule

This commit is contained in:
Jorijn van der Graaf 2026-10-02 20:42:21 +02:00
commit b51a5bffb0
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
3 changed files with 53 additions and 45 deletions

View file

@ -180,7 +180,8 @@ int main() {
Check(r.text.contains("G(x);"), "paren padding removed");
}
// naming: wrong-case function/type/static/global flagged; camel local passes.
// naming: wrong-case function/type/global flagged; camelCase local and
// static pass.
{
RuleRun r = RunRule("namespace {\n"
" std::int32_t bad_global = 0;\n"
@ -191,12 +192,44 @@ int main() {
" std::int32_t fineLocal = 1;\n"
"}\n",
"naming", LintMode::Report);
Check(HasFinding(r.summary, "'bad_global' should be PascalCase"), "lowercase global flagged");
Check(HasFinding(r.summary, "'bad_global' should be camelCase"), "snake_case global flagged");
Check(HasFinding(r.summary, "'lint_thing' should be PascalCase"), "lowercase type flagged");
Check(HasFinding(r.summary, "'lower_func' should be PascalCase"), "lowercase function flagged");
Check(HasFinding(r.summary, "'lowerStatic' should be PascalCase"), "camel static flagged");
Check(!HasFinding(r.summary, "lowerStatic"), "camelCase static passes");
Check(!HasFinding(r.summary, "fineLocal"), "camelCase local passes");
}
// naming: statics and constants are variables, so camelCase like any
// other wherever they live — a static local, a static or constexpr
// member, a namespace-scope constant or a plain global.
{
RuleRun r = RunRule("namespace {\n"
" constexpr int MaxSize = 4;\n"
" const int DEFAULT_PORT = 80;\n"
" static int kCount = 0;\n"
" int plainGlobal = 0;\n"
"}\n"
"struct Holder {\n"
" static int Instances;\n"
" static constexpr int kLimit = 8;\n"
" int Field = 0;\n"
"};\n"
"void Fn() {\n"
" static int Counter = 0;\n"
" static constexpr int localMax = 2;\n"
" (void)Counter;\n"
"}\n",
"naming", LintMode::Report);
Check(HasFinding(r.summary, "'MaxSize' should be camelCase"), "naming: PascalCase constexpr constant flagged");
Check(HasFinding(r.summary, "'DEFAULT_PORT' should be camelCase"), "naming: SCREAMING_CASE constant flagged");
Check(!HasFinding(r.summary, "kCount"), "naming: camelCase static global passes");
Check(!HasFinding(r.summary, "plainGlobal"), "naming: camelCase global passes");
Check(HasFinding(r.summary, "'Instances' should be camelCase"), "naming: PascalCase static member flagged");
Check(!HasFinding(r.summary, "kLimit"), "naming: camelCase static constexpr member passes");
Check(HasFinding(r.summary, "'Field' should be camelCase"), "naming: PascalCase member flagged");
Check(HasFinding(r.summary, "'Counter' should be camelCase"), "naming: PascalCase static local flagged");
Check(!HasFinding(r.summary, "localMax"), "naming: camelCase static constexpr local passes");
}
{
// Statement calls with inline lambda arguments are NOT function
// definitions (the any_of regression); a genuine lowercase one-liner
@ -351,16 +384,14 @@ int main() {
// Cases the line-based heuristic structurally could not see. It only looked
// at declarations starting at cumulative paren depth 0 and inferred scope
// from a running {/} count, so a wrapped signature, a specifier split over
// two lines, or a local shadowing a member all escaped it.
// from a running {/} count, so a wrapped signature or a local shadowing a
// member escaped it.
{
RuleRun r = RunRule("#include <string>\n"
"namespace Outer {\n"
" int wrapped_function(\n"
" int first,\n"
" int second) { return first + second; }\n"
" static\n"
" int splitStatic = 1;\n"
" struct Holder {\n"
" int Member = 0;\n"
" void Method() {\n"
@ -373,8 +404,6 @@ int main() {
"naming", LintMode::Report);
// A signature wrapped over lines is still a function declaration.
Check(HasFinding(r.summary, "'wrapped_function' should be PascalCase"), "naming: wrapped signature is seen");
// `static` on its own line still applies to the declaration below it.
Check(HasFinding(r.summary, "'splitStatic' should be PascalCase"), "naming: split specifier is seen");
// Members are camelCase; the enclosing kind decides, not a brace count.
Check(HasFinding(r.summary, "'Member' should be camelCase"), "naming: member is checked as a member");
// A local inside a method is a local, not a member and not a global.