Skip to main content

prefer-prefixed-global-constants

added in: 1.11.0
⚙️
preset: recommended

Warns when a global constant does not start with a configured prefix.

note

This rule does not take _ into account when checking the name.

⚙️ Config

Set allowed-prefixes (default is [k]) to configure allowed prefixes.

Set ignore-private (default is false) to ignore private variables.

dart_code_metrics:
...
rules:
...
- prefer-prefixed-global-constants:
allowed-names:
- myPrefix

Example

❌ Bad:

const String _nothing = '1'; // LINT
const String public = '1'; // LINT
const int _sValue = 1; // LINT

✅ Good:

const double _kMenuVerticalPadding = 1;
const double kPublic = 1.0;