eslint-plugin-sort-keys-fix

raw JSON →
1.1.2 verified Sat Apr 25 auth: no javascript

ESLint plugin that extends the built-in sort-keys rule with automatic fix capability. Version 1.1.2 is the latest stable release. This plugin sorts object keys alphabetically and provides autofix on save, unlike the core rule which only reports errors. It supports all native sort-keys options except minKeys and works with ESLint's --fix flag. Maintained as a fork with occasional updates, it's a convenient tool for enforcing consistent key ordering without manual effort.

error ESLint couldn't find the plugin "sort-keys-fix"
cause Plugin package not installed or not in node_modules.
fix
npm install eslint-plugin-sort-keys-fix --save-dev
error Configuration for rule "sort-keys-fix/sort-keys-fix" is invalid: Value "warn" is the wrong type. Expected array or string.
cause Rule configuration used without options specified incorrectly.
fix
Use severity string directly: "sort-keys-fix/sort-keys-fix": "warn"
error Definition for rule 'sort-keys-fix/sort-keys-fix' was not found.
cause Plugin not declared in plugins array, or rule name misspelled.
fix
Add 'plugins: ["sort-keys-fix"]' in ESLint config.
gotcha The rule only sorts top-level keys, not nested objects by default.
fix Use ESLint's --fix flag or editor integration to trigger autofix.
gotcha minKeys option from ESLint sort-keys is not supported.
fix Do not use minKeys option; it will be ignored or cause errors.
breaking Version 1.1.0 changed how spread operators are handled: property groups split by spread are now sorted separately.
fix Update to 1.1.2 or review sorting behavior for objects with spread operators.
npm install eslint-plugin-sort-keys-fix
yarn add eslint-plugin-sort-keys-fix
pnpm add eslint-plugin-sort-keys-fix

Enable the sort-keys-fix rule with autofix in ESLint config. Object keys will be sorted alphabetically.

// .eslintrc.json
{
  "plugins": ["sort-keys-fix"],
  "rules": {
    "sort-keys-fix/sort-keys-fix": ["warn", "asc", { "caseSensitive": true, "natural": false }]
  }
}

// file.js – will be fixed on save/--fix
const obj = {
  z: 1,
  a: 2
}; // fixed to { a: 2, z: 1 }