avoid_long_functions
This rule flags a function body longer than the configured line budget.
Why use this rule
Section titled “Why use this rule”A long function is not wrong, but it is where several responsibilities usually end up sharing one scope and one set of locals. Enforcing a budget in the analyzer puts the signal at the point of writing, where splitting is cheap, rather than in a CI script that reports it after the fact — which is what makes it a genuine replacement for a check_file_length.sh-style gate.
Lines are counted from the body’s braces, so the signature and any doc comment do not count against it.
This rule is in the pedantic preset. A budget is a house style, and the default of 50 is stricter than many codebases run: measured against a production Flutter app it reported 187 functions, median 98 lines — all genuinely long, none of them a bug. Override the budget when your project needs a different limit.
Test files usually want an exclusion
Section titled “Test files usually want an exclusion”A test main() legitimately runs to hundreds of lines, since every test(...) is one more statement in the same body. Scope the rule rather than raising the budget for everything:
rules: avoid_long_functions: exclude: - test/**void handleOrder(Order order) { // ... 80 lines validating, pricing, persisting and notifying}void handleOrder(Order order) { _validate(order); _price(order); _persist(order); _notify(order);}Enabling 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: avoid_long_functions: enabled: trueOptions
Section titled “Options”many_lints: rules: avoid_long_functions: max_lines: 80rules: avoid_long_functions: max_lines: 80| Option | Type | Default | Description |
|---|---|---|---|
max_lines |
int | 50 |
The longest body allowed, counted between the braces |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: avoid_long_functions: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_complex_conditions— Keep boolean conditions within an operand budget.avoid_deep_nesting— Keep control flow within a nesting budget.avoid_high_cyclomatic_complexity— Keep a function within a complexity budget.max_statements— Keep a function within a statement budget.