avoid_long_parameter_list
This rule flags a function taking more parameters than the configured budget.
Why use this rule
Section titled “Why use this rule”A long parameter list is usually several values that belong together travelling separately, and every caller has to assemble them in the right order. Grouping them into a record or a small class names the thing they form and makes the call sites read.
Positional and named parameters are counted separately, with a larger budget for named. Named parameters are labelled at the call site and do not depend on order, so a widget constructor with eight of them is not the problem this rule exists for — the default budgets are 4 positional and 10 named.
An @override is never reported, since it cannot change its signature.
This rule is in the pedantic preset: a parameter budget is a house style.
void schedule( String title, DateTime start, DateTime end, String venue, int courtNumber,) {}void schedule(String title, DateRange when, Court court) {}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_parameter_list: enabled: trueOptions
Section titled “Options”many_lints: rules: avoid_long_parameter_list: max_positional: 3 max_named: 12rules: avoid_long_parameter_list: max_positional: 3 max_named: 12| Option | Type | Default | Description |
|---|---|---|---|
max_positional |
int | 4 |
How many positional parameters are allowed |
max_named |
int | 10 |
How many named parameters are allowed |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: avoid_long_parameter_list: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_long_files— Keep a file within a line budget.avoid_too_many_methods— Keep a class within a method budget.max_imports— Keep a file within an import budget.avoid_long_functions— Keep function bodies within a line budget.