Skip to content

accessorPairGroups

Reports getter and setter accessors for the same property that are not adjacent.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

Grouping getters and setters together improves code readability. When a property has both a getter and a setter, defining them adjacent to each other makes it easier to understand how the property is accessed and modified.

class Example {
get value() {
return this._value;
}
otherMethod() {}
set value(newValue: number) {
this._value = newValue;
}
}
const object = {
get value() {
return this._value;
},
other: 42,
set value(newValue: number) {
this._value = newValue;
},
};

This rule is not configurable.

If you prefer a different organization style for class members, such as grouping by visibility or functionality, you might choose to disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.