Skip to main content

match-getter-setter-field-names

added in: 1.10.0
Pro+
preset: recommended

Warns when a getter or setter do not access at least one field with the name that matches the getter or setter name.

Example

❌ Bad:

class Point {
int _x;
int _y;

int get y => _x; // LINT: Suspicious getter implementation. Returned field name does not match the getter name. Try renaming it or referencing another field.
set y(int newValue) {
_x = newValue; // LINT: Suspicious setter implementation. Assigned field name does not match the setter name. Try renaming it or referencing another field.
}
}

✅ Good:

class Point {
int _x;
int _y;

int get y => _y;
set y(int newValue) {
_y = newValue;
}
}