Skip to main content

avoid-misused-wildcard-pattern

dart 3.0+
pro+

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

Example

❌ Bad:

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

// LINT: Avoid misused wildcard patterns. Try using another pattern instead.
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() && _) {}
}

✅ 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