{"record":{"id":"998856a9f8af2d0e","repo":"oxc-project/oxc","slug":"object-keys-should-be-sorted","errorCode":null,"errorMessage":"Object keys should be sorted","messagePattern":"Object keys should be sorted","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"info","filePath":"crates/oxc_linter/src/rules/eslint/sort_keys.rs","lineNumber":62,"sourceCode":"\nimpl Default for SortKeysOptions {\n    fn default() -> Self {\n        // we follow the eslint defaults\n        Self {\n            case_sensitive: true,\n            natural: false,\n            min_keys: 2,\n            allow_line_separated_groups: false,\n        }\n    }\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(default)]\npub struct SortKeysConfig(SortOrder, SortKeysOptions);\n\nfn sort_properties_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Object keys should be sorted\").with_label(span)\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// When declaring multiple properties, sorting property names alphabetically makes it easier\n    /// to find and/or diff necessary properties at a later time.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Unsorted property keys can make the code harder to read and maintain.\n    ///\n    /// ### Examples\n    ///\n    /// Examples of **incorrect** code for this rule:\n    /// ```js\n    /// let myObj = {\n    ///   c: 1,","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/sort_keys.rs#L44-L80","documentation":"oxlint `eslint/sort-keys`: an object expression's keys are not in ascending order and the object meets the minimum-size threshold, so `sort_properties_diagnostic` (sort_keys.rs:62) reports 'Object keys should be sorted'. Per the rule doc, sorted keys make properties easier to find and diff. The config (shown just above the diagnostic) supports `ignoreCase`, `natural`, `minKeys` (default 2), and `allowLineSeparatedGroups`.","triggerScenarios":"`const obj = { b: 1, a: 2 };` — an ObjectExpression with at least `minKeys` properties whose keys descend somewhere instead of ascending. Comparison is lexicographic by default, case-insensitive with `ignoreCase`, natural-order with `natural` (so `item2` < `item10`).","commonSituations":"Config objects and maps written in logical (not alphabetical) grouping; generated objects; enabling sort-keys on an existing codebase where every multi-key object is a hit.","solutions":["Sort the object's keys in ascending order.","Raise `minKeys` (e.g. 5) so small objects are exempt.","Set `natural: true` for human-friendly ordering of numbered keys, and `ignoreCase: true` to stop case churn.","Use `allowLineSeparatedGroups: true` and blank lines to keep semantically distinct groups sorted independently."],"exampleFix":"// before\nconst config = {\n  retries: 3,\n  baseUrl: 'https://api.example.com',\n  timeout: 1000,\n};\n\n// after\nconst config = {\n  baseUrl: 'https://api.example.com',\n  retries: 3,\n  timeout: 1000,\n};","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Tune the config before adopting: `minKeys`, `ignoreCase`, `natural`, and `allowLineSeparatedGroups` exist precisely to cut noise.","Use blank-line-separated groups for semantically distinct sections and enable `allowLineSeparatedGroups`.","For maps/config objects where logical order matters, prefer a `Map` or disable the rule for that object."],"tags":["eslint","oxlint","sorting","objects","style","lint"],"backgroundTag":"object-key-sorting","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"}