constant_identifier_names
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:
const PI = 3.14;
const kDefaultTimeout = 1000;
final URL_SCHEME = RegExp('^([a-z]+):');
class Dice {
static final NUMBER_GENERATOR = Random();
}
GOOD:
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:
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:
linter:
rules:
constant_identifier_names: true
Unless stated otherwise, the documentation on this site reflects Dart 3.6.0. Page last updated on 2025-01-27. View source or report an issue.