prefer-correct-identifier-length
Same as prefer-correct-identifier-length in Dart Code Metrics
- Group
- Style
- Path
lint/style/prefer-correct-identifier-length- Default
- Off, opt in
- Origin
- Dart Code Metrics
- Rule
- 339 of 512
Flags declared identifiers that are shorter or longer than the allowed range.
Very short names rarely convey meaning and very long ones hurt readability, so
this rule keeps declared names within a configurable length band. Its scope is
deliberately limited to variable and field declarations, getter and setter
names, and enum constants; parameters, catch-clause variables, for-each loop
variables, and plain function and method names are never checked, because
short names are often idiomatic there. A single leading underscore is stripped
before both the length and exception checks, so _id is judged as id.
Declarations in initializer closures, arrow bodies, operators, and enum
members follow the same policy as declarations in ordinary function bodies.
Options
min-length (int, default: 3) — flag identifiers shorter than this.
max-length (int, default: 300) — flag identifiers longer than this.
exceptions (list of strings, default: []) — names always allowed regardless of length.
Invalid
// Bad: too-short variable declarations, accessor names and enum constants.
void example() {
var a = compute();
final xy = a;
print(xy);
}
class Processor {
int m = 0;
String get n => '';
set v(String value) {}
}
// A C-style for-loop counter is a variable declaration, so it is checked.
void loop(List<int> items) {
for (var i = 0; i < items.length; i++) {
print(items[i]);
}
}
enum Size { s, m, l }
// A Dart 3 destructuring declaration declares variables, so every name the
// pattern binds is length-checked — records, lists, and nested patterns alike.
void patternDeclarations(List<int> items) {
final (a, b) = (1, 2);
final [c, d] = items;
final (e, (f, _)) = (1, (2, 3));
print([a, b, c, d, e, f]);
}
// A declaration inside a labeled block or a closure body is reached too.
void nestedDeclarations() {
lbl: {
final gg = 1;
print(gg);
}
final callback = () {
final hh = 2;
return hh;
};
print(callback);
}
final topCallback = () {
final aa = 1;
return aa;
};
class ClosureDeclarations {
final callback = () {
final bb = 2;
return bb;
};
Object arrow() => () {
final cc = 3;
return cc;
};
int operator +(int value) {
final dd = value;
return dd;
}
}
enum MemberDeclarations {
value;
int read() {
final ee = 4;
return ee;
}
}
class InitializerDeclarations {
final Object callback;
InitializerDeclarations() : callback = (() {
final ff = 5;
return ff;
});
}
List<int> collectionLoop(int count) => [
for (var w = 0; w < count; w++) w,
];void example() { var a = compute(); var a = compute(); final xy = a;class Processor { int m = 0; String get n => ''; set v(String value) {}void loop(List<int> items) { for (var i = 0; i < items.length; i++) { enum Size { s, m, l } enum Size { s, m, l } enum Size { s, m, l }void patternDeclarations(List<int> items) { final (a, b) = (1, 2);void patternDeclarations(List<int> items) { final (a, b) = (1, 2); final (a, b) = (1, 2); final [c, d] = items; final (a, b) = (1, 2); final [c, d] = items; final [c, d] = items; final (e, (f, _)) = (1, (2, 3)); final [c, d] = items; final (e, (f, _)) = (1, (2, 3)); lbl: { final gg = 1; final callback = () { final hh = 2;final topCallback = () { final aa = 1; final callback = () { final bb = 2; Object arrow() => () { final cc = 3; int operator +(int value) { final dd = value; int read() { final ee = 4; InitializerDeclarations() : callback = (() { final ff = 5;List<int> collectionLoop(int count) => [ for (var w = 0; w < count; w++) w,Valid
// Good: identifiers meet the minimum length (3), plus dcl's scope exemptions.
// dcl only checks variable declarations, getter/setter names and enum
// constants — never parameters, catch clauses, for-each variables, or plain
// method/function names.
void example() {
var count = compute();
final result = count + 1;
print(result);
}
class Processor {
String path = '';
int id = 0; // `id` is in the exceptions list
int _id = 0; // leading underscore stripped -> `id` -> exempt
// Method name (`at`) and parameters (`i`, `j`) are out of scope.
int at(int i, int j) => i + j;
// Getter name is >= 3 characters.
String get label => path;
}
// Parameters, catch clauses and for-each variables are never checked, so short
// names here are fine.
void shortLived(int a, int b) {
try {
print(a + b);
} catch (e) {
print(e);
}
for (final x in [1, 2, 3]) {
print(x);
}
}
enum Color { red, green, blue }Configure prefer-correct-identifier-length
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-correct-identifier-length": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-correct-identifier-length: <reason>More style rules
- prefer-correct-notifier-file-nameriverpod
Requires
snake_casefile names ending in _notifier.dart for resolved Riverpod notifier classes. - prefer-correct-provider-file-nameriverpod
Requires
snake_casefile names ending in _provider.dart for resolved Riverpod provider declarations, including annotated generator functions. - prefer-correct-test-file-nametest
Requires entry-point files under package-root test/ or
integration_test/ to use the _test.dart suffix. - prefer-correct-type-name
prefer-correct-type-nameFlags type declarations whose name is not well-formed
UpperCamelCase. - prefer-dedicated-media-query-methods
prefer_dedicated_media_query_methodsrecommendedflutterFlags
MediaQuery.of(context).sizeaccess in favor ofMediaQuery.sizeOf. - prefer-double-quotes
prefer_double_quotesFlags single-quoted string literals that could use double quotes without needing an escape.
- prefer-early-return
Flags a trailing
ifthat wraps multiple statements in a void function. - prefer-equatable-mixinequatable
Prefer
EquatableMixinto directly extending package:equatable's Equatable.