avoid-passing-default-values
Warns when an invocation has an argument that matches the parameter's default value.
warning
If you are depending on external API, you might want to keep explicitly passed default values in case this API changes. Consider that before enabling this rule.
⚙️ Config
Set ignored-parameters
(default is empty) to ignore specific named parameters.
Set ignored-values
(default is empty) to ignore specific default values.
dart_code_metrics:
...
rules:
...
- avoid-passing-default-values:
ignored-parameters:
- someName
ignored-values:
- false
- MyEnum.someValue
- SomeClass.staticVariable
Example
❌ Bad:
class WithString {
final String value;
const WithString({this.value = 'some'});
}
void main() {
WithString(value: 'some'); // LINT
}
✅ Good:
class WithString {
final String value;
const WithString({this.value = 'some'});
}
void main() {
WithString(value: 'another');
}