max_statements
This rule flags a function that executes more statements than the configured budget.
Why use this rule
Section titled “Why use this rule”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);}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: max_statements: enabled: trueOptions
Section titled “Options”many_lints: rules: max_statements: max_statements: 25rules: max_statements: max_statements: 25| Option | Type | Default | Description |
|---|---|---|---|
max_statements |
int | 25 |
How many statements a function may execute |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: max_statements: 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.avoid_long_functions— Keep function bodies within a line budget.