oxc-project/oxc · warning · OxcDiagnostic

Accessor pair {getter_key} and {setter_key} should be groupe

Error message

Accessor pair {getter_key} and {setter_key} should be grouped.

What it means

Oxlint's port of the ESLint rule grouped-accessor-pairs (crates/oxc_linter/src/rules/eslint/grouped_accessor_pairs.rs:29): when a property has both a getter and a setter (in an object literal or class body), they must be adjacent, and per the PairOrder enum optionally ordered — `anyOrder` (default, grouping only), `getBeforeSet`, or `setBeforeGet`. The diagnostic receives a prebuilt message plus both keys and spans, and labels each accessor with '{key} is here'.

Source

Thrown at crates/oxc_linter/src/rules/eslint/grouped_accessor_pairs.rs:35

use serde::{Deserialize, Serialize};
use serde_json::Value;

use crate::{
    AstNode,
    context::LintContext,
    rule::{Rule, TupleRuleConfig},
};

fn grouped_accessor_pairs_diagnostic(
    getter_span: Span,
    getter_key: &str,
    setter_span: Span,
    setter_key: &str,
    msg: String,
) -> OxcDiagnostic {
    let getter_label_span = getter_span.label(format!("{getter_key} is here"));
    let setter_label_span = setter_span.label(format!("{setter_key} is here"));
    OxcDiagnostic::warn(msg)
        .with_help("Require grouped accessor pairs in object literals and classes")
        .with_labels([getter_label_span, setter_label_span])
}

#[derive(Debug, Default, PartialEq, Clone, Copy, JsonSchema, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
enum PairOrder {
    /// Accessors can be in any order. This is the default.
    #[default]
    AnyOrder,
    /// Getters must come before setters.
    GetBeforeSet,
    /// Setters must come before getters.
    SetBeforeGet,
}

#[derive(Debug, Default, Clone, JsonSchema, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", default)]

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Move the getter and setter onto adjacent lines.
  2. Order them to match the configured pairOrder (getBeforeSet is the common convention).
  3. If grouping and order do not matter to the team, disable the rule.

Example fix

// before
const cfg = {
  get port() { return this._p; },
  timeout: 30,
  set port(v) { this._p = v; },
};

// after
const cfg = {
  timeout: 30,
  get port() { return this._p; },
  set port(v) { this._p = v; },
};
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json — enforce grouping plus getter-first order
{
  "rules": {
    "grouped-accessor-pairs": ["warn", "getBeforeSet"]
  }
}

Prevention

When it happens

Trigger: A `get value()` and `set value(v)` separated by other members in the same object literal or class under any mode; or accessors in the wrong order relative to a configured getBeforeSet/setBeforeGet.

Common situations: Large object literals where accessors drift apart as properties get inserted between them; enabling getBeforeSet on a codebase with mixed order; merging config objects.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/b43c7fa97ab7d1d9. Report an issue: GitHub.