Skip to main content

avoid-long-parameter-list

added in: 1.2.0
⚙️

Long parameter lists are difficult to understand and use. Wrapping them into an object allows grouping parameters and change transferred data only by the object modification. When you're working with objects, you should pass just enough so that the method can get the data it needs.

⚙️ Config

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

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

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

dart_code_metrics:
...
rules:
...
- avoid-long-parameter-list:
ignore-optional: true
max-amount: 3
ignored-names:
- some
- name

Example

❌ Bad:

void someFunction(
String firstParameter, String secondParameter, String thirdParameter, String forthParameter) { // LINT
return;
}

✅ Good:

void someFunction(SomeWrapper wrapped) {
return;
}

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