Skip to main content

avoid-long-parameter-list

added in: 1.2.0
⚙️
Pro+

Warns then a parameter list has too many parameters.

Long parameter lists are difficult to understand and use. Wrapping several parameters into an object allows grouping parameters and simplifies the parameter list. When you're working with functions or methods, you should pass just enough so that the function gets only the data it needs.

⚙️ Config

Set ignore-optional (default is false) to exclude optional and named parameters (example).

Set ignored-names (default is copyWith) to ignore specific function / method names.

Set max-number (default is 5) to configure the number of parameters after which the rule should trigger.

analysis_options.yaml
dart_code_metrics:
rules:
- avoid-long-parameter-list:
ignore-optional: false
max-number: 3
ignored-names:
- some
- name

Example

❌ Bad:

void someFunction(
// LINT: Avoid long parameter list. Try refactoring the declaration or moving some parameters to a new wrapper object.
String firstParameter, String secondParameter, String thirdParameter, String forthParameter) {
return;
}

✅ Good:

void someFunction(SomeWrapper wrapped) {
return;
}

class SomeWrapper {
final String firstParameter;
final String secondParameter;
final String thirdParameter;
final String forthParameter;

const SomeWrapper(...);
}

Example with "ignore-optional"

Config
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-long-parameter-list:
ignore-optional: true
max-number: 3

✅ Good:

void someFunction(
// Correct, two parameters are excluded
String firstParameter, String secondParameter, [String? thirdParameter, String? forthParameter]) {
return;
}