Skip to content

unicorn/no-accessor-recursion Suspicious

What it does

Disallow recursive access to this within getters and setters

Why is this bad?

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

Examples

Examples of incorrect code for this rule:

js
const foo = {
  get bar() {
    return this.bar;
  },
};

Examples of correct code for this rule:

js
const foo = {
  get bar() {
    return this.baz;
  },
};

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny unicorn/no-accessor-recursion
json
{
  "rules": {
    "unicorn/no-accessor-recursion": "error"
  }
}

References

Released under the MIT License.