match-getter-setter-field-names
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;
}
}