accessorPairGroups
Reports getter and setter accessors for the same property that are not adjacent.
✅ This rule is included in the tsstylisticandstylisticStrictpresets.
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.
Examples
Section titled “Examples”class class Example
Example { get Example.value: number
value() { return this._value;Error ts(2551) ― } Example.otherMethod(): void
otherMethod() {} set Example.value: number
value(newValue: number
newValue: number) { this._value = newValue: number
newValue;Error ts(2551) ― }}const const object: { value: number; other: number;}
object = { get value: number
value() { return this._value;Error ts(2551) ― }, other: number
other: 42, set value: number
value(newValue: number
newValue: number) { this._value = newValue: number
newValue;Error ts(2551) ― },};class class Example
Example { get Example.value: number
value() { return this._value;Error ts(2551) ― } set Example.value: number
value(newValue: number
newValue: number) { this._value = newValue: number
newValue;Error ts(2551) ― } Example.otherMethod(): void
otherMethod() {}}const const object: { value: number; other: number;}
object = { get value: number
value() { return this._value;Error ts(2551) ― }, set value: number
value(newValue: number
newValue: number) { this._value = newValue: number
newValue;Error ts(2551) ― }, other: number
other: 42,};Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you prefer a different organization style for class members, such as grouping by visibility or functionality, you might choose to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
useaccessorPairGroups - ESLint:
grouped-accessor-pairs - Oxlint:
eslint/grouped-accessor-pairs
Made with ❤️🔥 around the world by
the Flint team and contributors.