keyword_on_wildcard
Reports var or final before a wildcard of a pattern. Delete the keyword.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- deletes the keyword
What it reports
Section titled “What it reports”var or final before a wildcard of a pattern: case final _:, if (value case var _), final int _ =>, Point(x: final _). The violation is on the keyword.
It does not report:
- the loop variable
for (final _ in items)or a declarationfinal _ = start();, which are not patterns; - a named pattern variable.
A wildcard binds no variable, so there is nothing for the keyword to make final. final _ matches what _ matches, and final int _ what int _ matches.
Example
Section titled “Example”Violating
int kind(Object value) => switch (value) { final int _ => 1, _ => 0,};Corrected
int kind(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: keyword_on_wildcard// ignore_for_file: assay/keyword_on_wildcard silences it in a whole file, and // ignore: assay/keyword_on_wildcard with the prefix works too. See Suppressions.