avoid-redundant-pattern-field-names
Same as avoid_redundant_pattern_field_names in Pyramid Lint
- Group
- Style
- Path
lint/style/avoid-redundant-pattern-field-names- Default
- On (recommended)
- Origin
- Pyramid Lint
- Rule
- 123 of 512
Flags redundant field names in object and record patterns.
When a pattern binds a field to a variable of the same name — Point(x: x)
or (name: name) — the explicit label merely repeats the getter name for no
benefit. The shorthand Point(:x) / (:name) is shorter and equivalent.
Only a field whose label matches its bound variable is flagged; a genuine
rename such as Point(x: px) is left alone.
Invalid
class Point {
final int x;
final int y;
const Point(this.x, this.y);
}
void objectPatterns(Object o) {
switch (o) {
case Point(
x: x,
y: y,
):
print('$x$y');
default:
break;
}
}
void ifCase(Object o) {
if (o case Point(x: x)) {
print(x);
}
}
int switchExpr(Object o) => switch (o) {
Point(y: y) => y,
_ => 0,
};
void recordPattern(Object o) {
switch (o) {
case (
first: first,
second: second,
):
print('$first$second');
default:
break;
}
} case Point( x: x, x: x, y: y,void ifCase(Object o) { if (o case Point(x: x)) {int switchExpr(Object o) => switch (o) { Point(y: y) => y, case ( first: first, first: first, second: second,Valid
class Point {
final int x;
final int y;
const Point(this.x, this.y);
}
void shorthand(Object o) {
switch (o) {
case Point(:final x, :final y):
print('$x$y');
default:
break;
}
}
void renamed(Object o) {
switch (o) {
case Point(x: final a, y: final b):
print('$a$b');
default:
break;
}
}
void differentNames(Object o) {
if (o case Point(x: y)) {
print(y);
}
}
int switchExpr(Object o) => switch (o) {
Point(:final x) => x,
_ => 0,
};
void records(Object o) {
switch (o) {
case (first: final a, second: final b):
print('$a$b');
default:
break;
}
}Configure avoid-redundant-pattern-field-names
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-redundant-pattern-field-names": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-redundant-pattern-field-names: <reason>More style rules
- avoid-renaming-method-parameters
avoid_renaming_method_parametersRequires overriding methods to keep the positional parameter names of the member they inherit.
- avoid-return-types-on-setters
avoid_return_types_on_settersrecommendedFlags setters declared with an explicit return type.
- avoid-returning-this
avoid_returning_thisFlags methods that return
thisonly to enable a fluent interface. - avoid-setters-without-getters
avoid_setters_without_gettersFlags a setter that has no corresponding getter.
- avoid-single-cascade-in-expression-statements
avoid_single_cascade_in_expression_statementsrecommendedFlags an expression statement that is a cascade with a single section.
- avoid-single-child-column-or-row
avoid_single_child_column_or_rowflutterFlags a
Column,Row, orFlexwidget built with a single child. - avoid-top-level-member-access
Flags mutable global state: non-
const, non-finaltop-level variables and static fields, plus every read of mutable top-level variables. - avoid-types-on-closure-parameters
avoid_types_on_closure_parametersFlags type annotations on closure parameters whose types come from context.