Skip to main content

avoid_unused_parameters

Warns about unused function, method, constructor, or factory parameters.

Named parameters are always allowed because they document the API surface. Parameters whose names consist only of underscores are also ignored. Overridden methods and methods used as tear-offs are skipped.

Example config:

plugins:
solid_lints:
diagnostics:
avoid_unused_parameters:
exclude:
- class_name: MyClass
method_name: myMethod
exclude_annotation:
- freezed

Example

BAD:

typedef MaxFun = int Function(int a, int b);
final MaxFun bad = (int a, int b) => 1; // LINT
final MaxFun testFun = (int a, int b) { // LINT
return 4;
};
final optional = (int a, [int b = 0]) { // LINT
return a;
};

void fun(String x) {} // LINT
void fun2(String x, String y) { // LINT
print(y);
}

class TestClass {
static void staticMethod(int a) {} // LINT
void method(String s) {} // LINT

TestClass([int a]); // LINT
factory TestClass.named(int a) { // LINT
return TestClass();
}
}

GOOD:

typedef MaxFun = int Function(int a, int b);
final MaxFun good = (int a, int b) => a + b;
final MaxFun testFun = (int a, int b) {
return a + b;
};
void fun(String _) {} // Replacing with underscores silences the warning
void fun2(String _, String y) {
print(y);
}

class TestClass {
static void staticMethod(int _) {}
void method(String _) {}

TestClass([int _]);
factory TestClass.named(int _) {
return TestClass();
}
}

Allowed:

typedef Named = String Function({required String text});
final Named named = ({required text}) {
return '';
};

Parameters

exclude (String | Map | List<String | Map>)

A list of methods that should be excluded from the lint.

exclude_annotation (String | List<String>)

A list of annotations that should be ignored during class check.