Skip to main content

match-getter-setter-field-names

added in: 1.10.0
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 x => _x;
set x(int newValue) {
_x = newValue;
}

int get y => _x; // LINT
set y(int newValue) {
_x = newValue; // LINT
}
}

✅ Good:

class Point {
int _x;
int _y;

int get x => _x;
set x(int newValue) {
_x = newValue;
}

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