avoid-banned-names
Warns against using banned names (e.g. a variable or class name).
note
This rule requires configuration in order to highlight any issues.
⚙️ Config
Set entries (default is empty) to configure the list of entries for usages to ban.
Each entry is an object with 4 fields (name (or name-pattern), path, exclude-paths and severity):
- Set
nameto configure the identifier name (to pass a regular expression, setname-patterninstead). - Set
name-pattern(optional) to configure a regular expression for the identifier name. - Set
severity(optional) to override default severity for the given entry. - Set
paths(optional) to configure the list of regular expressions that the entry will apply to. If unset, applies to all files. - Set
exclude-paths(can be a regular expression, optional) to configure the list of paths the entry will not apply to. - Set
message(optional) to configure a user-facing message for each issue created from this config entry.
analysis_options.yaml
dcm:
rules:
- avoid-banned-names:
entries:
- name: strangeMethod
- name: StrangeClass
- name: strangeName
Example
❌ Bad:
void func() {
var strangeName = 42; // LINT: Avoid banned names. Try renaming this declaration.
}
void strangeName() {} // LINT: Avoid banned names. Try renaming this declaration.
// LINT: Avoid banned names. Try renaming this declaration.
class StrangeClass {
late var strangeName; // LINT: Avoid banned names. Try renaming this declaration.
bool strangeMethod() {} // LINT: Avoid banned names. Try renaming this declaration.
}
✅ Good:
void func() {
var another = 42; // Correct, different name
}
void method() {}
class SomeClass {
bool strangeMethod() {}
}