changed rule
This commit is contained in:
parent
88139fc0fc
commit
b51a5bffb0
3 changed files with 53 additions and 45 deletions
|
|
@ -132,8 +132,12 @@ void AddRules(Crafter::Configuration& cfg) {
|
|||
}
|
||||
});
|
||||
|
||||
// Naming: types and functions PascalCase, variables camelCase, with
|
||||
// statics, namespace-scope globals and constexpr constants PascalCase.
|
||||
// Naming: types and functions PascalCase, everything that holds a value
|
||||
// camelCase — locals, members, globals, statics and constants alike.
|
||||
// Storage and constness used to pick the case, which meant `static int x`
|
||||
// and `namespace { int x; }` were spelled differently for no reason a
|
||||
// reader could see; now where a variable lives changes nothing about
|
||||
// its name.
|
||||
//
|
||||
// Reads the AST. The previous version needed four std::regex, a hand-rolled
|
||||
// {/} scope stack, a cumulative paren-depth counter to avoid mistaking a
|
||||
|
|
@ -150,10 +154,6 @@ void AddRules(Crafter::Configuration& cfg) {
|
|||
// A declaration with C language linkage is named by the C library
|
||||
// it mirrors — `extern "C" int setenv(...)` is not ours to rename.
|
||||
if (decl.isExternC) continue;
|
||||
// Namespace scope is now a lookup rather than a brace count, and it
|
||||
// is exact for a local declared inside a function body.
|
||||
bool atNamespaceScope = decl.parent == Crafter::LintNoParent
|
||||
|| decls[decl.parent].kind == Kind::Namespace;
|
||||
switch (decl.kind) {
|
||||
case Kind::Class:
|
||||
case Kind::Struct:
|
||||
|
|
@ -179,26 +179,13 @@ void AddRules(Crafter::Configuration& cfg) {
|
|||
}
|
||||
break;
|
||||
case Kind::Variable:
|
||||
// constexpr variables are compile-time constants and take
|
||||
// constant naming, like statics and globals.
|
||||
if (decl.isStatic || decl.isConstexpr || atNamespaceScope) {
|
||||
if (!IsPascalCase(decl.name)) {
|
||||
ctx.Report(decl.line, std::format("{} '{}' should be PascalCase",
|
||||
decl.isStatic ? "static variable"
|
||||
: decl.isConstexpr ? "constexpr constant"
|
||||
: "global variable", decl.name));
|
||||
}
|
||||
} else if (!IsCamelCase(decl.name)) {
|
||||
ctx.Report(decl.line, std::format("variable '{}' should be camelCase", decl.name));
|
||||
}
|
||||
break;
|
||||
case Kind::Field:
|
||||
if (decl.isStatic || decl.isConstexpr) {
|
||||
if (!IsPascalCase(decl.name)) {
|
||||
ctx.Report(decl.line, std::format("static member '{}' should be PascalCase", decl.name));
|
||||
}
|
||||
} else if (!IsCamelCase(decl.name)) {
|
||||
ctx.Report(decl.line, std::format("member '{}' should be camelCase", decl.name));
|
||||
// A static data member arrives as a Variable whose parent
|
||||
// is the class; a Field is a per-instance member. Both
|
||||
// are camelCase, so the label is the only difference.
|
||||
if (!IsCamelCase(decl.name)) {
|
||||
ctx.Report(decl.line, std::format("{} '{}' should be camelCase",
|
||||
decl.kind == Kind::Field ? "member" : "variable", decl.name));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
Loading…
Reference in a new issue