close

grouped-accessor-pairs

Unreleased

Configuration

rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'grouped-accessor-pairs': 'error',
    },
  },
]);

Rule Details

This rule requires getter and setter definitions for the same property to be adjacent in object literals and classes. It can also enforce whether the getter or setter appears first and, when configured, checks TypeScript interface and type-literal accessors.

Examples of incorrect code for this rule:

const value = {
  get name() {},
  other: true,
  set name(next) {},
};

Examples of correct code for this rule:

const value = {
  get name() {},
  set name(next) {},
  other: true,
};

Examples of incorrect code for this rule with "getBeforeSet":

{ "grouped-accessor-pairs": ["error", "getBeforeSet"] }
const value = {
  set name(next) {},
  get name() {},
};

Examples of incorrect TypeScript code when type accessors are enforced:

{
  "grouped-accessor-pairs": [
    "error",
    "anyOrder",
    { "enforceForTSTypes": true }
  ]
}
interface Value {
  get name(): string;
  other: boolean;
  set name(next: string);
}

Original Documentation