# grouped-accessor-pairs

> Require the getter and setter of a property to be next to each other

When other members sit between a property's getter and setter, someone who finds the getter can miss that there's a setter further down.

The rule checks object literals and classes. In a class, a static pair and an instance pair with the same name are separate.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"grouped-accessor-pairs" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"grouped-accessor-pairs" = [
  "error",
  "anyOrder", # "anyOrder", "getBeforeSet" or "setBeforeGet"
  {
    enforceForTSTypes = false,
  },
]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
class User {
  get name() {
    return this.first;
  }
  save() {}
  set name(value) {
    this.first = value;
  }
}
```

Not reported:

{/* good */}
```js
class User {
  get name() {
    return this.first;
  }
  set name(value) {
    this.first = value;
  }
  save() {}
}
```

## Options

```toml bunfig.toml
[lint.rules]
grouped-accessor-pairs = ["error", "getBeforeSet"]
```

| Option | What it does |
| --- | --- |
| `"anyOrder"` (default) | The pair must be adjacent, in either order. |
| `"getBeforeSet"` | The getter must also come first. |
| `"setBeforeGet"` | The setter must also come first. |

| Option | Default | What it does |
| --- | --- | --- |
| `enforceForTSTypes` | `false` | Also check `get` and `set` signatures in interfaces and type literals. |

{/* bad {"options": ["getBeforeSet"]} */}
```js
const volume = {
  set level(value) {
    this.raw = value;
  },
  get level() {
    return this.raw;
  },
};
```

{/* good {"options": ["getBeforeSet"]} */}
```js
const volume = {
  get level() {
    return this.raw;
  },
  set level(value) {
    this.raw = value;
  },
};
```

### `enforceForTSTypes`

{/* good */}
```ts
interface Volume {
  get level(): number;
  mute(): void;
  set level(value: number);
}
```

{/* bad {"options": ["anyOrder", {"enforceForTSTypes": true}]} */}
```ts
interface Volume {
  get level(): number;
  mute(): void;
  set level(value: number);
}
```
