# no-accessor-recursion

Rule `unicorn/no-accessor-recursion`. Disallow recursive access to `this` within getters and setters.

- Source: unicorn
- Technologies: JavaScript
- Kind: suspicious
- Needs type information: no
- Autofix: no
- Reach: 12M weekly downloads of presets that enable it
- Trend: +40.1% last quarter
- Rank: #772 by reach, #968 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-accessor-recursion` | no | no | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-accessor-recursion.md) |
| Oxlint | `unicorn/no-accessor-recursion` | no | no | plugin `unicorn`, category suspicious | [docs](https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-accessor-recursion.html) |

## Code examples

### Incorrect: the rule reports this

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

```js
class Foo {
  get bar() {
    return this.bar;
  }
}
```

```js
const foo = {
  set bar(value) {
    this.bar = value;
  }
};
```

### Correct: the rule accepts this

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

```js
class Foo {
  get bar() {
    return this.baz;
  }
}
```

```js
const foo = {
  set bar(value) {
    this._bar = value;
  }
};
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-accessor-recursion": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "unicorn/no-accessor-recursion": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/no-abusive-eslint-disable](https://lintradar.dev/rules/unicorn/no-abusive-eslint-disable.md): Enforce specifying rules to disable in `eslint-disable` comments.
- [unicorn/no-anonymous-default-export](https://lintradar.dev/rules/unicorn/no-anonymous-default-export.md): Disallow anonymous functions and classes as the default export.
- [unicorn/explicit-timer-delay](https://lintradar.dev/rules/unicorn/explicit-timer-delay.md): Enforce or disallow explicit `delay` argument for `setTimeout()` and `setInterval()`.
- [unicorn/no-array-fill-with-reference-type](https://lintradar.dev/rules/unicorn/no-array-fill-with-reference-type.md): Disallow using reference values as `Array#fill()` values.
- [unicorn/prefer-query-selector](https://lintradar.dev/rules/unicorn/prefer-query-selector.md): Prefer `.querySelector()` and `.querySelectorAll()` over older DOM query methods.
- [unicorn/no-array-method-this-argument](https://lintradar.dev/rules/unicorn/no-array-method-this-argument.md): Disallow using the `this` argument in array methods.

---

Web page: https://lintradar.dev/rules/unicorn/no-accessor-recursion. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
