wildcard_type_matches_everything
Reports a type on a wildcard in a case pattern that every matched value already has, as in Object _. Write the bare _.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- deletes the type
What it reports
Section titled “What it reports”The type of a wildcard in a case pattern that every value matched there has: case Object? _:, dynamic _, Object _ on a value that cannot be null, Shape _ on a Shape, Point(x: int _) where the field is an int, [int _, ...] on a List<int>. The violation covers the type.
- The type is judged against the static type of the value it matches: it tests nothing where that type is a subtype of it.
- A matched
dynamicvalue has every type, so there onlyObject?anddynamictest nothing. - Only case patterns are looked at: switch statements, switch expressions, if-case. In a declaration or an assignment, the pattern’s types are the context of the value, which deleting one could change.
The fix deletes the type; a keyword before it stays, which keyword_on_wildcard reports. It is not offered where a comment stands in the type or before the name.
The type tests nothing, so _ alone matches the same and says so.
Example
Section titled “Example”int describe(Object value) => switch (value) { int() => 1, Object _ => 0,};int describe(Object value) => switch (value) { int() => 1, _ => 0,};Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Why it stays as written here.// ignore: assay/wildcard_type_matches_everything// ignore_for_file: assay/wildcard_type_matches_everything silences it in a whole file, and // ignore: wildcard_type_matches_everything without the prefix works too. See Suppressions.