prefer_prefixed_global_constants
v1.0.0WarningConfigurableClass Naming
many_lints.yaml
analysis_options.yaml many_lints.yaml
many_lints.yaml
This rule flags a public top-level constant that does not carry the configured prefix.
A top-level constant is in scope everywhere the library is imported, under a name that competes with every local. defaultTimeout at the top level reads identically to a local of the same name at the point of use, so a prefix — kDefaultTimeout, Flutter’s own convention — makes the origin visible without a jump to the declaration.
Only public constants are checked: a private one cannot collide outside its own library, which is the problem the prefix solves.
This rule is in no preset.
const defaultTimeout = Duration(seconds: 30);const kDefaultTimeout = Duration(seconds: 30);Enabling this rule
Section titled “Enabling this rule”This rule reports nothing until you choose a prefix, since there is no defensible default:
rules: prefer_prefixed_global_constants: prefix: kOptions
Section titled “Options”many_lints: rules: prefer_prefixed_global_constants: prefix: krules: prefer_prefixed_global_constants: prefix: k| Option | Type | Default | Description |
|---|---|---|---|
prefix |
string | — |
The required prefix. Unset means the rule is silent |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: prefer_prefixed_global_constants: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_unnecessary_enum_prefix— Drop an enum name repeated in its own constants.match_class_name_pattern— Match class names against a regular expression.prefer_boolean_prefixes— Name booleans as questions.prefer_correct_callback_field_name— Name callbacks onSomething, the way Flutter does.