Skip to main content

avoid-keywords-in-wildcard-pattern

added in: 1.7.0
🛠
Dart 3.0+

Warns when a wildcard pattern has declaration keywords.

Example

❌ Bad:

void fn() {
final animal = 'hello';

final value = switch (animal) {
final Object? _ => 'bad', // LINT
var _ => 'bad', // LINT
final _ => 'bad', // LINT
};
}

✅ Good:

void fn() {
final animal = 'hello';

final value = switch (animal) {
Object? _ => 'good',
_ => 'good',
Object _ => 'good',
};
}