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
- Reorder the members so `set x(v)` appears immediately before `get x()` in the same body.
- Change the configuration to `"order": "anyOrder"` (default, grouping-only) or `"getBeforeSet"` to match the existing code convention.
- 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
- Fix the `order` value deliberately (anyOrder | getBeforeSet | setBeforeGet) when porting an ESLint config — a wrong enum silently reorders expectations.
- Keep getter/setter pairs adjacent when editing class members; separated accessors also trip the grouping half of the rule.
- Codemods (e.g. oxfmt or jscodeshift) that move class members are a common source of order flips — re-lint immediately after running them.
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
- Expected {getter_key} to be before {setter_key}.
- Accessor pair {getter_key} and {setter_key} should be groupe
- Expected shorthand for all properties.
- Expected longform property syntax.
- Expected longform method syntax.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/8164bb3099e1632d.
Report an issue: GitHub.