Skip to content

avoid_banned_names

v1.0.0WarningConfigurableArchitecture

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.

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't
void process(int temp) {} // LINT
class Manager {} // LINT
final users = fetchUsers();
void process(int celsius) {}
class UserDirectory {}

This rule is in no preset, so it is off unless you enable it by name:

many_lints.yaml
rules:
avoid_banned_names: true

To turn it off again:

many_lints.yaml
rules:
avoid_banned_names: false

To keep the rule on but skip certain paths, use per-rule exclude.

analysis_options.yaml
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.'
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

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.