prefer-named-parameters
Suggests converting positional parameters to named parameters when a declaration has a certain number of positional parameters.
With positional parameters, it's relatively easy to pass the wrong argument to a parameter (especially after a certain number of declared parameters). This rule helps avoid such mistakes.
⚙️ Config
Set max-number
(default is 1
) to configure the number of allowed positional parameters.
analysis_options.yaml
dart_code_metrics:
rules:
- prefer-named-parameters:
max-number: 1
Example
❌ Bad:
class Some {
final String value;
final String another;
// LINT: Number of positional parameters exceeds the configured maximum of 1. Try converting the exceeding parameters to named parameters.
const Some(this.value, this.another);
}
✅ Good:
class Some {
final String value;
final String another;
const Some(this.value, {required this.another});
}