invalid-case-patterns
Same as invalid_case_patterns in Dart lints
- Group
- Correctness
- Path
lint/correctness/invalid-case-patterns- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 247 of 512
Flags pre-3.0 switch case expressions that change meaning or break under Dart 3 patterns.
Dart 3 reinterprets case operands as patterns. Code still on a pre-3.0
language version can prepare for the migration by avoiding case expressions
that are invalid or mean something different as patterns: non-const list,
map, or set literals; implicitly-const constructor calls; identical(...)
calls; prefix operators on anything but an integer literal; binary,
conditional and is expressions; .length accesses whose receiver, after
unwrapping parentheses, is not an identifier; and the identifier _ (a
wildcard in Dart 3). The receiver test applies to ordinary and null-aware
accesses alike. The lint applies only to libraries whose language version
predates 3.0, where falcon parses case operands as expressions.
Invalid
// @dart = 2.19
class Point {
const Point(this.x);
final int x;
}
void check(Object? value, bool a, bool b) {
switch (value) {
case [1, 2]:
break;
case {'a': 1}:
break;
case Point(1):
break;
case identical(1, 2):
break;
case _:
break;
case (<int>[]):
break;
}
} switch (value) { case [1, 2]: break; case {'a': 1}: break; case Point(1): break; case identical(1, 2): break; case _: break; case (<int>[]):Valid
// @dart = 2.19
class Point {
const Point(this.x);
final int x;
}
const origin = Point(0);
void check(Object? value) {
switch (value) {
case const [1, 2]:
break;
case const {'a': 1}:
break;
case const Point(1):
break;
case origin:
break;
case -1:
break;
case 'text':
break;
case null:
break;
}
}Configure invalid-case-patterns
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"invalid-case-patterns": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/invalid-case-patterns: <reason>More correctness rules
- invalid-runtime-check-with-js-interop-types
invalid_runtime_check_with_js_interop_typesrecommendedReject platform-dependent runtime checks involving JavaScript interop types.
- library-private-types-in-public-api
library_private_types_in_public_apirecommendedAvoid using library-private types in public APIs.
- list-all-equatable-fieldsrecommendedequatable
Flags declared instance fields omitted from a statically understood Equatable props list.
- literal-only-boolean-expressions
literal_only_boolean_expressionsrecommendedFlags conditions built only from literals, whose value never changes.
- match-getter-setter-field-names
Detect likely copy-paste errors in trivial accessors when a different field matching the accessor name is declared.
- missing-test-assertionrecommendedtest
Reports inline test callbacks that contain no recognized assertion calls.
- no-adjacent-strings-in-list
no_adjacent_strings_in_listrecommendedFlags adjacent string literals used as an element of a list or set literal.
- no-import-cyclescross-file
Report mutually dependent components of imported or exported library files.