{"record":{"id":"8164bb3099e1632d","repo":"oxc-project/oxc","slug":"expected-setter-key-to-be-before-getter-key","errorCode":null,"errorMessage":"Expected {setter_key} to be before {getter_key}.","messagePattern":"Expected (.+?) to be before (.+?)\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/grouped_accessor_pairs.rs","lineNumber":35,"sourceCode":"use serde::{Deserialize, Serialize};\nuse serde_json::Value;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{Rule, TupleRuleConfig},\n};\n\nfn grouped_accessor_pairs_diagnostic(\n    getter_span: Span,\n    getter_key: &str,\n    setter_span: Span,\n    setter_key: &str,\n    msg: String,\n) -> OxcDiagnostic {\n    let getter_label_span = getter_span.label(format!(\"{getter_key} is here\"));\n    let setter_label_span = setter_span.label(format!(\"{setter_key} is here\"));\n    OxcDiagnostic::warn(msg)\n        .with_help(\"Require grouped accessor pairs in object literals and classes\")\n        .with_labels([getter_label_span, setter_label_span])\n}\n\n#[derive(Debug, Default, PartialEq, Clone, Copy, JsonSchema, Serialize, Deserialize)]\n#[serde(rename_all = \"camelCase\")]\nenum PairOrder {\n    /// Accessors can be in any order. This is the default.\n    #[default]\n    AnyOrder,\n    /// Getters must come before setters.\n    GetBeforeSet,\n    /// Setters must come before getters.\n    SetBeforeGet,\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Serialize, Deserialize)]\n#[serde(rename_all = \"camelCase\", default)]","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/grouped_accessor_pairs.rs#L17-L53","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nconst state = {\n  get value() { return this._v; },\n  set value(v) { this._v = v; },\n}\n\n// after (order: \"setBeforeGet\")\nconst state = {\n  set value(v) { this._v = v; },\n  get value() { return this._v; },\n}","handlingStrategy":"validation","validationCode":"// Decide the convention first, then validate against it:\n// .oxlintrc.json -> \"rules\": { \"grouped-accessor-pairs\": [\"error\", { \"order\": \"setBeforeGet\" }] }\n// Then run oxlint in CI to fail before merge.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["eslint","oxlint","style","accessor","getter","setter","object-literal"],"backgroundTag":"accessor-pair-ordering","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}