Skip to content

max_statements

v1.0.0WarningConfigurableCode Quality

This rule flags a function that executes more statements than the configured budget.

This is the counterpart to avoid_long_functions, measuring what a function does rather than how much room it takes. The two disagree in exactly the useful cases: a function of twenty short statements is long by both measures, while one holding a single wide widget tree is long by lines only, and splitting it would help nobody.

Statements are counted through nested blocks, so a loop body counts toward the function that owns it. A nested function expression is counted on its own — a callback is separate work, not more of the enclosing function’s.

This rule is in the pedantic preset: a budget is a house style, and the right number differs per codebase.

void handleSubmit() {
// 30 statements: validation, mapping, the request, error handling,
// analytics, and navigation, all in one scope.
}
void handleSubmit() {
final input = _validate();
if (input == null) return;
_submit(input);
}

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

many_lints.yaml
rules:
max_statements:
enabled: true
analysis_options.yaml
many_lints:
rules:
max_statements:
max_statements: 25
Option Type Default Description
max_statements int 25 How many statements a function may execute

To disable this rule:

many_lints.yaml
rules:
max_statements: false

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