constant_identifier_names
Prefer using lowerCamelCase for constant names.
This rule is available as of Dart 2.0.
Rule sets: recommended, flutter
This rule has a quick fix available.
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();
}
Usage
#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
Unless stated otherwise, the documentation on this site reflects Dart 3.6.0. Page last updated on 2024-07-03. View source or report an issue.