avoid-long-parameter-list
added in: 1.2.0
warning
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.
Use ignore-optional
configuration (default is false
), if you want to exclude optional parameters from parameters counter.
Use ignored-names
configuration (default is copyWith
), if you want to ignore specific function / method names.
Use max-amount
configuration (default is 5
), to set up the number of parameters after which the rule should trigger.
⚙️ Config example
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;
}