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:
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();
}
Usage
#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
除非另有说明,文档之所提及适用于 Dart 3.6.0 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。