Rules / Style / constant-identifier-names
constant-identifier-names
Flags constant identifiers that are not lowerCamelCase.
Dart names constants in lowerCamelCase, not the SCREAMING_CAPS common in
other languages, so maxCount rather than MAX_COUNT. Following the
convention keeps constants visually consistent with every other identifier.
The rule covers const declarations at every scope — top-level, static and
instance fields, and locals — as well as enum values. All-underscore
wildcard names are permitted.
Invalid
example.dartdart
// Constant identifiers must be lowerCamelCase.
const MAX_VALUE = 100;
const PI = 3.14;
const HTTP_PORT = 80;
enum E { FIRST, second }
class C {
static const DEFAULT_SIZE = 10;
}
void f() {
const LOCAL_CONST = 1;
print(LOCAL_CONST);
}
Name constant identifiers using lowerCamelCase.
2
3const MAX_VALUE = 100;
∙
Name constant identifiers using lowerCamelCase.
Name constant identifiers using lowerCamelCase.
6
7const HTTP_PORT = 80;
∙
Name constant identifiers using lowerCamelCase.
8
9enum E { FIRST, second }
∙
Name constant identifiers using lowerCamelCase.
11class C {
12 static const DEFAULT_SIZE = 10;
∙
Name constant identifiers using lowerCamelCase.
15void f() {
16 const LOCAL_CONST = 1;
∙
Valid
example.dartdart
// lowerCamelCase constant identifiers.
const maxValue = 100;
const pi = 3.14;
const httpPort = 80;
enum E { first, second }
class C {
static const defaultSize = 10;
}
void f() {
const localConst = 1;
print(localConst);
}
How to configure
Set the severity of constant-identifier-names in your falcon.json:
falcon.jsonjson
{
"linter": {
"rules": {
"style": {
"constant-identifier-names": "error"
}
}
}
}