avoid_banned_names
Flags declarations named with an identifier you ban, optionally only inside the directories you name. Enforces a project’s vocabulary: ban data, temp and manager as meaningless, or reserve a domain term for the one thing it should mean.
This rule reports nothing until you configure it.
Why use this rule
Section titled “Why use this rule”Names like data, info, temp and manager survive because they are never wrong — every value is data and every class manages something. That is exactly what makes them useless: they tell the next reader nothing the type did not already say, and they cluster, so a file ends up with data, userData and dataList in one scope.
A banned-name list is also how a team keeps a domain term precise. If Order means a customer purchase, banning it as a variable name for a sort order stops the two senses from mixing in the same codebase.
See also: Effective Dart: naming, Dart style guide: do use terms consistently
// With an entry banning 'data', 'temp', 'manager':final data = fetchUsers(); // LINT: says nothing the type didn'tvoid process(int temp) {} // LINTclass Manager {} // LINTfinal users = fetchUsers();
void process(int celsius) {}
class UserDirectory {}Turning this rule off
Section titled “Turning this rule off”This rule is in no preset, so it is off unless you enable it by name:
rules: avoid_banned_names: trueTo turn it off again:
rules: avoid_banned_names: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Options
Section titled “Options”many_lints: rules: avoid_banned_names: banned: - deny: ['data', 'temp', 'info', 'manager'] message: 'Name it for what it holds.' - deny_pattern: ['.*Impl'] message: 'Name the implementation for how it differs.'rules: avoid_banned_names: banned: - deny: ['data', 'temp', 'info', 'manager'] message: 'Name it for what it holds.' - deny_pattern: ['.*Impl'] message: 'Name the implementation for how it differs.'| Option | Type | Default | Description |
|---|---|---|---|
banned |
list of maps | [] |
The entries to enforce. With none, the rule reports nothing |
Each entry accepts:
| Key | Type | Required | Description |
|---|---|---|---|
deny |
string or list | one of deny / deny_pattern |
Identifiers banned by exact match |
deny_pattern |
string or list | one of deny / deny_pattern |
Regular expressions, anchored to the whole name |
in |
list of globs | no | Paths, relative to the package root, where the entry applies. Omit to apply everywhere |
message |
string | no | A project-specific explanation appended to the diagnostic |
What is checked
Section titled “What is checked”Variables, parameters, methods, functions, classes, mixins, enums, extension types, and type parameters — every place a name is chosen.
References are deliberately not reported. A reference is not separately fixable (renaming the declaration fixes every use), so reporting them would bury the one line you can act on under diagnostics you cannot.
Because deny matches exactly, banning data leaves userData and dataSource alone. Use deny_pattern to match by shape — and note it anchors to the whole name, so .*Impl matches UserImpl but not ImplementationDetail.
Related rules
Section titled “Related rules”avoid_banned_annotations— Ban specific annotations, optionally scoped by directory.avoid_banned_exports— Ban re-exports of specific libraries, optionally scoped by directory.avoid_banned_imports— Ban imports of specific libraries, optionally scoped by directory.avoid_banned_types— Ban specific types from being named, optionally scoped by directory.