constant_identifier_names

Stable
Recommended
Fix available

Prefer using lowerCamelCase for constant names.

Details

#

PREFER using lowerCamelCase for constant names.

In new code, use lowerCamelCase for constant variables, including enum values.

In existing code that uses ALL_CAPS_WITH_UNDERSCORES for constants, you may continue to use all caps to stay consistent.

BAD:

dart
const PI = 3.14;
const kDefaultTimeout = 1000;
final URL_SCHEME = RegExp('^([a-z]+):');

class Dice {
  static final NUMBER_GENERATOR = Random();
}

GOOD:

dart
const pi = 3.14;
const defaultTimeout = 1000;
final urlScheme = RegExp('^([a-z]+):');

class Dice {
  static final numberGenerator = Random();
}

Enable

#

To enable the constant_identifier_names rule, add constant_identifier_names under linter > rules in your analysis_options.yaml file:

analysis_options.yaml
yaml
linter:
  rules:
    - constant_identifier_names

If you're instead using the YAML map syntax to configure linter rules, add constant_identifier_names: true under linter > rules:

analysis_options.yaml
yaml
linter:
  rules:
    constant_identifier_names: true