Skip to content

avoid_long_parameter_list

v1.0.0WarningConfigurableCode Quality

This rule flags a function taking more parameters than the configured budget.

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

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

many_lints.yaml
rules:
avoid_long_parameter_list:
enabled: true
analysis_options.yaml
many_lints:
rules:
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

To disable this rule:

many_lints.yaml
rules:
avoid_long_parameter_list: false

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