Skip to content

avoid_long_functions

v1.0.0WarningConfigurableCode Quality

This rule flags a function body longer than the configured line budget.

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.

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);
}

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

many_lints.yaml
rules:
avoid_long_functions:
enabled: true
analysis_options.yaml
many_lints:
rules:
avoid_long_functions:
max_lines: 80
Option Type Default Description
max_lines int 50 The longest body allowed, counted between the braces

To disable this rule:

many_lints.yaml
rules:
avoid_long_functions: false

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