oxc-project/oxc · warning · OxcDiagnostic

Expected {setter_key} to be before {getter_key}.

Error message

Expected {setter_key} to be before {getter_key}.

What it means

Emitted by the oxlint rule `grouped-accessor-pairs` when configured with `order: "setBeforeSet"`'s counterpart `"setBeforeGet"` — i.e. the config requires setters to come first, but the getter for a key appears before the setter in the same object literal or class body. Like its sibling diagnostic, it is a style lint warning produced from the pair-order check that compares the getter and setter positions, and it labels both accessor spans.

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. Reorder the members so `set x(v)` appears immediately before `get x()` in the same body.
  2. Change the configuration to `"order": "anyOrder"` (default, grouping-only) or `"getBeforeSet"` to match the existing code convention.
  3. Suppress for the specific site with `oxlint-disable-next-line grouped-accessor-pairs` if the order is intentional and config-wide change is not desired.

Example fix

// before
const state = {
  get value() { return this._v; },
  set value(v) { this._v = v; },
}

// after (order: "setBeforeGet")
const state = {
  set value(v) { this._v = v; },
  get value() { return this._v; },
}
Defensive patterns

Strategy: validation

Validate before calling

// Decide the convention first, then validate against it:
// .oxlintrc.json -> "rules": { "grouped-accessor-pairs": ["error", { "order": "setBeforeGet" }] }
// Then run oxlint in CI to fail before merge.

Prevention

When it happens

Trigger: Configuration `{ "grouped-accessor-pairs": ["error", { "order": "setBeforeGet" }] }` combined with `class A { get x() {} set x(v) {} }` or an object literal like `{ get x() { ... }, set x(v) { ... } }`. The rule fires when `setter_idx > getter_idx` under the SetBeforeGet ordering (crates/oxc_linter/src/rules/eslint/grouped_accessor_pairs.rs:474).

Common situations: Codebases that adopted a setter-first convention (some framework code and older Java-style ports do); ESLint-to-oxlint config migration where the JSON config carried `order: "setBeforeGet"`; refactors that move getters above setters while the lint config expects the opposite order.

Related errors


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