prefer-underscore-for-unused-callback-parameters
Same as prefer_underscore_for_unused_callback_parameters in Pyramid Lint
- Group
- Style
- Path
lint/style/prefer-underscore-for-unused-callback-parameters- Default
- Off, opt in
- Origin
- Pyramid Lint
- Rule
- 415 of 512
Flags unused closure parameters that are not named with underscores.
Invalid
// Bad: unused callback parameter should be named _
void example1() {
final items = [1, 2, 3];
items.forEach((item) {
print('hello');
});
}
void example2() {
final map = {'a': 1, 'b': 2};
map.forEach((key, value) {
print('hello');
});
}
void example3() {
final items = ['x', 'y'];
items.map((element) => 'mapped').toList();
}
void example4() {
final numbers = [1, 2, 3];
numbers.where((n) => true).toList();
}
// Bad: unused parameter in reduce-like operation
void example5() {
final values = [1, 2, 3, 4];
values.fold(0, (previous, current) => previous + 1);
}
// Bad: unused index parameter in indexed map
void example6() {
final items = ['a', 'b', 'c'];
items.asMap().forEach((index, value) {
print(value);
});
}
void shadowedCallback(List<int> items) {
items.forEach((value) {
final nested = (value) => value + 1;
for (final value in items) {
print(nested(value));
}
});
} final items = [1, 2, 3]; items.forEach((item) { final map = {'a': 1, 'b': 2}; map.forEach((key, value) { final items = ['x', 'y']; items.map((element) => 'mapped').toList(); final numbers = [1, 2, 3]; numbers.where((n) => true).toList(); final values = [1, 2, 3, 4]; values.fold(0, (previous, current) => previous + 1); final items = ['a', 'b', 'c']; items.asMap().forEach((index, value) {void shadowedCallback(List<int> items) { items.forEach((value) {Valid
// Good: unused callback parameters renamed to _
void example1() {
final items = [1, 2, 3];
items.forEach((_) {
print('hello');
});
}
void example2() {
final map = {'a': 1, 'b': 2};
map.forEach((_, __) {
print('hello');
});
}
void example3() {
final items = ['x', 'y'];
items.map((_) => 'mapped').toList();
}
void example4() {
final numbers = [1, 2, 3];
numbers.where((_) => true).toList();
}
void example5() {
final items = [1, 2, 3];
items.forEach((item) {
print(item);
});
}
void example6() {
final map = {'a': 1, 'b': 2};
map.forEach((key, value) {
print('$key: $value');
});
}
// A genuine interpolated read counts as a use of the callback parameter.
void interpolatedRead(List<int> items) {
items.map((value) => "n=$value").toList();
items.map((value) => "n=${value + 1}").toList();
}
void sourceOrderCallback(List<int> items) {
items.forEach((value) {
print(value);
{
final value = 1;
print(value);
}
});
}
void capturedCallback(List<int> items) {
items.forEach((value) {
final nested = () => value;
print(nested());
});
}
void unbracedCallbackScope(List<int> items) {
items.forEach((value) {
if (items.isEmpty) int value = 0;
print(value);
});
}Configure prefer-underscore-for-unused-callback-parameters
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-underscore-for-unused-callback-parameters": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-underscore-for-unused-callback-parameters: <reason>More style rules
- prefer-void-callbackflutter
Prefers Flutter's
VoidCallbackalias over a nongenericvoid Function()type. - provide-deprecation-message
provide_deprecation_messagerecommendedFlags
@deprecatedand@Deprecated()annotations that carry no message. - public-member-api-docs
public_member_api_docsDocuments public declarations and members in package libraries.
- record-fields-ordering
Flags named record type fields that violate the configured order.
- require-trailing-commas
require_trailing_commasFlags a multi-line call, declaration, assert, or collection literal that is missing a trailing comma.
- sized-box-shrink-expand
sized_box_shrink_expandrecommendedflutterPrefers
SizedBox.shrink()/SizedBox.expand()over aSizedBoxsized to zero or infinity. - slash-for-doc-comments
slash_for_doc_commentsrecommendedFlags
/** ... - sort-child-properties-last
sort_child_properties_lastrecommendedflutterSort Widget-valued child properties last, except before closure arguments.