prefer_correct_identifier_length
This rule flags an identifier shorter or longer than the configured bounds.
A one-letter name outside a tiny scope forces the reader to hold a mapping the code never states, and a forty-character one is usually a sentence that belongs in a doc comment.
Both bounds are house style, which is why this rule ships with generous defaults and an exception list rather than an opinion. The conventional short names are exempt out of the box — loop counters, coordinates, the e of a catch clause — through allow_names, which adds to that built-in set rather than replacing it.
A private name’s leading underscore is a modifier, not part of its length, so _id counts as two characters.
This rule is in the pedantic preset.
final q = compute();final theCompletelyUnnecessarilyVerboseResultHolder = compute();final quota = compute();final result = compute();
for (var i = 0; i < 3; i++) {} // conventional short names are exemptEnabling this rule
Section titled “Enabling this rule”This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:
rules: prefer_correct_identifier_length: enabled: trueOptions
Section titled “Options”many_lints: rules: prefer_correct_identifier_length: min_length: 2 max_length: 40 additional_allow_names: [id]rules: prefer_correct_identifier_length: min_length: 2 max_length: 40 additional_allow_names: [id]| Option | Type | Default | Description |
|---|---|---|---|
min_length |
int | 2 |
Shortest allowed identifier |
max_length |
int | 40 |
Longest allowed identifier |
allow_names |
list | built-in set |
Names exempt from both bounds; use additional_allow_names to extend rather than replace |
additional_allow_names |
list | [] |
Names to add without replacing the built-in set |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: prefer_correct_identifier_length: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”match_class_name_pattern— Match class names against a regular expression.prefer_correct_type_name— Keep type names within a sensible length and correctly capitalised.use_class_prefix— Require a name prefix for classes deriving from a configured type.use_class_suffix— Require a name suffix for classes deriving from a configured type.