Skip to content

prefer_correct_identifier_length

v1.0.0WarningConfigurableClass Naming

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 exempt

This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:

many_lints.yaml
rules:
prefer_correct_identifier_length:
enabled: true
analysis_options.yaml
many_lints:
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

To disable this rule:

many_lints.yaml
rules:
prefer_correct_identifier_length: false

To keep the rule on but skip certain paths, use per-rule exclude.