prefer-wildcard-pattern
preset: recommended
Warns when a dynamic
or Object
type is used instead of a wildcard pattern.
Although it's not a mistake to use them, patterns provide a better option to match unknown value called a wildcard pattern _
.
Example
❌ Bad:
final object = WithField('hello');
final value = switch (object) {
WithField() => 'good',
Object() => 'bad', // LINT: Prefer the wildcard pattern '_' instead.
dynamic() => 'bad', // LINT: Prefer the wildcard pattern '_' instead.
};
✅ Good:
final object = WithField('hello');
final value = switch (object) {
WithField() => 'good',
_ => 'good',
};