no-accessor-recursion

March 27, 2026 ยท View on GitHub

๐Ÿ“ Disallow recursive access to this within getters and setters.

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

This rule prevents recursive access to this within getter and setter methods in objects and classes, avoiding infinite recursion and stack overflow errors.

Examples

// โŒ
const foo = {
	get bar() {
		return this.bar;
	}
};

// โœ…
const foo = {
	get bar() {
		return this.baz;
	}
};
// โŒ
class Foo {
	get bar() {
		return this.bar;
	}
}

// โœ…
class Foo {
	get bar() {
		return this.baz;
	}
}
// โŒ
const foo = {
	set bar(value) {
		this.bar = value;
	}
};

// โœ…
const foo = {
	set bar(value) {
		this._bar = value;
	}
};
// โŒ
class Foo {
	set bar(value) {
		this.bar = value;
	}
}

// โœ…
class Foo {
	set bar(value) {
		this._bar = value;
	}
}