declared-name-pattern
What it does
Section titled “What it does”Reports a name that a command declares when it does not match the pattern of its class, for languages whose files are a flat list of commands (CMake). The option names says which argument of which command is a name and of which class (command:position:class), markers and scopes settle the class of a variable (a marker word among the arguments, or the innermost listed block it is set in), and patterns gives each class a regex that the name must match from its start. A class without a pattern is not checked. reference_start and reference_end cut references such as ${...} out of a name first, and ignore_pattern leaves matching names out.
Why it matters
Section titled “Why it matters”A naming convention is only useful when it holds everywhere: with it, a reader can tell from the name what kind of thing it is, and a search finds all of one kind. Without the option rows the rule checks nothing.
To fix, rename the variable or function.
Example
Section titled “Example”set(lower 1)set(UPPER 1)set(lc "" CACHE STRING "x")set(_OK "" CACHE INTERNAL "x")set(lc2 "" CACHE STRING INTERNAL)set(ENV{any} 1)set(${x} 1)set(${x}_a 1)list(LENGTH UPPER out)foreach(Item a b)endforeach()function(F_n Arg) set(Local 1) set(local 1) set(xy 1 PARENT_SCOPE)endfunction()macro(m) set(xy 1) set(XY 1)endmacro()Configuration
Section titled “Configuration”lint: rules: declared-name-pattern: level: warn # off (default), warn, error options: names: [] markers: [] scopes: [] patterns: [] reference_start: "" reference_end: "" ignore_pattern: ""| Option | Type | Default | Description |
|---|---|---|---|
names |
list | [] |
Rows command:position:class (command may be command FIRST-ARGUMENT): the argument at the position (0, -1 for the last, or 1+ for the rest) are names of the class; the class variable is told by markers and scopes. |
markers |
list | [] |
Rows WORD:class: a command with the argument WORD (or the arguments WORD WORD, in a row) declares a variable of the class; the last row that fits wins. |
scopes |
list | [] |
Rows block:class: a variable set inside the block that starts with the command block (the innermost listed one) has the class; the row with no block is the class outside them. An empty class is not checked. |
patterns |
list | [] |
Rows class:regex: the regex a name of the class must match from its start. |
reference_start |
string | "" |
Where a reference to another name starts inside a name (${ in CMake); the references, up to the matching reference_end, are cut out before the name is matched, and a name that is only references is left out. |
reference_end |
string | "" |
Where a reference ends (} in CMake). |
ignore_pattern |
string | "" |
A regex; a name that matches is left out. |
Enabled by the presets: cmake/cmake-lint.
Suppress one line with sudsy-disable-next-line declared-name-pattern in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| cmake-lint | C0103 |
full |