{"record":{"id":"b2e585fca7f2760d","repo":"oxc-project/oxc","slug":"expected-getter-key-to-be-before-setter-key","errorCode":null,"errorMessage":"Expected {getter_key} to be before {setter_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":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Swap the two accessors so the `get x()` member appears directly before `set x(v)` in the same class or object literal.","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.","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."],"exampleFix":"// before\nclass Person {\n  set name(v) { this._name = v; }\n  get name() { return this._name; }\n}\n\n// after\nclass Person {\n  get name() { return this._name; }\n  set name(v) { this._name = v; }\n}","handlingStrategy":"validation","validationCode":"// Pre-commit check: enforce getter-before-setter ordering in edited object/class bodies.\n// Or simply run: oxlint --rule grouped-accessor-pairs='{\"order\":\"getBeforeSet\"}' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt one accessor ordering convention per repo and encode it once in .oxlintrc.json instead of relying on reviews.","Enable editor-time oxlint (LSP) so ordering mistakes are highlighted on save, before CI.","When pasting accessor pairs, check that get precedes set; make it a review checklist item for class-heavy PRs."],"tags":["eslint","oxlint","style","accessor","getter","setter","class"],"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-14T05:17:10.506Z"}