Skip to main content

avoid-misused-wildcard-pattern

added in: 1.7.0
Dart 3.0+
Pro+

Warns when a wildcard pattern is used in the wrong context.

Example

❌ Bad:

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

if (animal.isEmpty case _) {} // LINT: Avoid misused wildcard patterns. Try using another pattern instead.

final (Object _) = animal; // LINT: Avoid misused wildcard patterns. Try using another pattern instead.

if (animal.isEmpty case bool() && _) {} // LINT: Avoid misused wildcard patterns. Try using another pattern instead.
}

✅ Good:

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

if (animal.isEmpty case final isEmpty) {} // Correct, different pattern

final (Object object) = animal;

if (animal.isEmpty case final bool isEmpty) {}
}

Additional Resources