Skip to main content

prefer-prefixed-global-constants

added in: 1.11.0
⚙️
Pro+
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.

analysis_options.yaml
dart_code_metrics:
rules:
- prefer-prefixed-global-constants:
allowed-prefixes:
- k
ignore-private: false

Example

❌ Bad:

const String _nothing = '1'; // LINT: Prefer to prefix global constants with one of the configured prefixes: k.
const String public = '1'; // LINT: Prefer to prefix global constants with one of the configured prefixes: k.
const int _sValue = 1; // LINT: Prefer to prefix global constants with one of the configured prefixes: k.

✅ Good:

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