oxc-project/oxc · warning · OxcDiagnostic

Expected {getter_key} to be before {setter_key}.

Error message

Expected {getter_key} to be before {setter_key}.

What it means

This diagnostic comes from the oxlint rule `grouped-accessor-pairs` (ported from ESLint's grouped-accessor-pairs). It is emitted when the rule is configured with `order: "getBeforeSet"` and a setter for a key appears in source before the getter for the same key, in the same object literal or class body. It is a stylistic lint warning, not a runtime error; both the getter and setter spans are labeled so you can see the offending pair.

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. Swap the two accessors so the `get x()` member appears directly before `set x(v)` in the same class or object literal.
  2. If deliberate reordering is too invasive, relax the config to `"order": "anyOrder"` (the default, which then only checks grouping) or switch to `"setBeforeGet"` if that is the team convention.
  3. Turn the rule off for the file with an `oxlint-disable grouped-accessor-pairs` comment, or disable it in `.oxlintrc.json` when the project has no ordering convention.

Example fix

// before
class Person {
  set name(v) { this._name = v; }
  get name() { return this._name; }
}

// after
class Person {
  get name() { return this._name; }
  set name(v) { this._name = v; }
}
Defensive patterns

Strategy: validation

Validate before calling

// Pre-commit check: enforce getter-before-setter ordering in edited object/class bodies.
// Or simply run: oxlint --rule grouped-accessor-pairs='{"order":"getBeforeSet"}' src/

Prevention

When it happens

Trigger: Enable the rule with configuration `{ "grouped-accessor-pairs": ["error", { "order": "getBeforeSet" }] }` and write `class A { set x(v) {} get x() {} }` or `const o = { set x(v) {}, get x() {} }`. The diagnostic fires because the getter's index in the member list is greater than the setter's for the same property key.

Common situations: Teams migrating an ESLint config that enforces getter-first ordering to oxlint; refactoring a class and accidentally reordering accessors; code generated by tools that emit setters before getters; copy-pasting an accessor pair from code written under a setBeforeGet convention.

Related errors


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