Skip to main content

match-getter-setter-field-names

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;

// LINT: Suspicious getter implementation. Returned field name does not match the getter name.
// Try renaming it or referencing another field.
int get y => _x;

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

✅ Good:

class Point {
int _x;
int _y;

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