Skip to main content

avoid-banned-names

added in: 1.21.0
⚙️
Pro+

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 3 fields (name (or name-pattern), path and severity):

  • Set name to configure the identifier name (to pass a regular expression, set name-pattern instead).
  • 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.
analysis_options.yaml
dart_code_metrics:
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() {}
}