avoid-unused-parameters
preset: recommended
Checks for unused parameters inside a function or method body.
For overridden methods suggests renaming unused parameters to _, __, etc.
info
Abstract classes are completely ignored by the rule to avoid redundant checks for potentially overridden methods.
⚙️ Config
Set ignore-inline-functions
(default is true
) to ignore inline functions (example). Default value is set to true
for backward compatibility and can be changed in the future.
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-unused-parameters:
ignore-inline-functions: true
Example
❌ Bad:
void someFunction(String s) { // LINT: Parameter is not used. Try removing it, renaming to _ or referencing it in code.
return;
}
class SomeClass {
void method(String s) { // LINT: Parameter is not used. Try removing it, renaming to _ or referencing it in code.
return;
}
}
class SomeClass extends AnotherClass {
void method(String s) {} // LINT: Parameter is not used. Try removing it, renaming to _ or referencing it in code.
}
✅ Good:
void someOtherFunction() {
return;
}
class SomeOtherClass {
void method() {
return;
}
}
void someOtherFunction(String s) {
print(s);
return;
}
class SomeOtherClass {
void method(String s) {
print(s);
return;
}
}
class SomeOtherClass extends AnotherClass {
void method(String _) {}
}
abstract class SomeOtherClass {
void method(String s);
}
Example with "ignore-inline-functions"
Config
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-unused-parameters:
ignore-inline-functions: false
❌ Bad:
class TestClass {
void _someNamedCallback({required Function(String, int) callback}) {
callback();
}
void _anotherMethod() {
// LINT: Parameter is not used. Try removing it, renaming to _ or referencing it in code.
_someNamedCallback(callback: (value, counter) {
print(value);
});
}
}