Skip to content

prefer_prefixed_global_constants

v1.0.0WarningConfigurableClass Naming

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);

This rule reports nothing until you choose a prefix, since there is no defensible default:

many_lints.yaml
rules:
prefer_prefixed_global_constants:
prefix: k
analysis_options.yaml
many_lints:
rules:
prefer_prefixed_global_constants:
prefix: k
Option Type Default Description
prefix string The required prefix. Unset means the rule is silent

To disable this rule:

many_lints.yaml
rules:
prefer_prefixed_global_constants: false

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