# eslint-plugin-sort-keys-custom-order

> Enforce keys sorting on objects and TS types in a custom order with autofix

Latest version **3.1.2** (published 2026-07-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-sort-keys-custom-order
pnpm add eslint-plugin-sort-keys-custom-order
yarn add eslint-plugin-sort-keys-custom-order
bun add eslint-plugin-sort-keys-custom-order
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.1.2 |
| Published | 2026-07-31 |
| First published | 2021-06-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 29.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Hugo Attal |
| Maintainers | hugoattal |
| Keywords | eslint, eslintplugin, eslint-plugin, typescript |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-sort-keys-custom-order
- Repository: https://github.com/hugoattal/eslint-plugin-sort-keys-custom-order
- Homepage: https://github.com/hugoattal/eslint-plugin-sort-keys-custom-order#readme
- Issues: https://github.com/hugoattal/eslint-plugin-sort-keys-custom-order/issues
- npm.io page: https://npm.io/package/eslint-plugin-sort-keys-custom-order

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@inrupt/eslint-config-base](https://npm.io/package/@inrupt/eslint-config-base.md) — 4.5K weekly downloads

## Recent versions

- 3.1.2 (latest) — 2026-07-31
- 3.1.1 — 2026-07-31
- 3.1.0 — 2026-07-31
- 3.0.3 — 2026-07-05
- 3.0.2 — 2026-04-07
- 3.0.1 — 2026-02-11
- 3.0.0 — 2026-02-11
- 2.2.1 — 2024-11-19
- 2.2.0 — 2024-10-22
- 2.1.0 — 2024-07-28
- 2.0.2 — 2024-07-15
- 2.0.1 — 2024-07-15
- 2.0.0 — 2024-07-13
- 1.0.5 — 2022-11-27
- 1.0.4 — 2022-11-27
- … 4 more at https://npm.io/package/eslint-plugin-sort-keys-custom-order/versions

## README

# eslint-plugin-sort-keys-custom-order

This plugin enforces alphabetically sorting keys in objects and typescript types with auto-fix. You can add a list of priority sorted keys for custom sorting (ex: if you want "id" to be the first property).

## Installation

You'll first need to install [ESLint](http://eslint.org):

```
$ npm install -D eslint
```

Next, install `eslint-plugin-sort-keys-custom-order`:

```
$ npm install -D eslint-plugin-sort-keys-custom-order
```


## Usage

Add `sort-keys-custom-order` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

```js
// eslint.config.js
import sortKeysCustomOrder from "eslint-plugin-sort-keys-custom-order";

export default [{
    /* ... */
    plugins: {
        "sort-keys-custom-order": sortKeysCustomOrder
    }
    /* ... */
}]
```


Then configure the rules you want to use under the rules section.

```js
// .eslintrc.js
export default [{
    /* ... */
    "rules": {
        // For JS objects sorting
        "sort-keys-custom-order/object-keys": [
            "error", { "orderedKeys": ["id", "name", "title"] }
        ],
        // For TS types sorting
        "sort-keys-custom-order/type-keys": [
            "error", { "orderedKeys": ["id", "name", "title"] }
        ]
    }
    /* ... */
}]
```

Or you can use the recommended configuration:

```js
// eslint.config.js
import sortKeysCustomOrder from "eslint-plugin-sort-keys-custom-order";

export default [
    /* ... */
    sortKeysCustomOrder.configs["flat/recommended"],
    /* ... */
]
```

## Configuration

`orderedKeys: Array<string>` : You can pass an array of ordered keys to the rule configuration. The rule will sort the keys in the order you provided.

`sorting: "asc" | "desc" | "none"` : You can pass the sorting order for the keys not in orderedKeys. Default is "asc".

Example:

```json
{
    "sort-keys-custom-order/object-keys": [
        "error", 
        { 
            "orderedKeys": ["id","name","title"],
            "sorting": "asc"
        }
    ]
}
```


## Supported Rules

### sort-keys-custom-order/object-keys

Allow you to sort properties inside JS objects

### sort-keys-custom-order/type-keys

Allow you to sort properties inside TS types

### sort-keys-custom-order/import-object-keys

Allow you to sort properties inside JS import objects

### sort-keys-custom-order/export-object-keys

Allow you to sort properties inside JS export objects


## Example

```js
// Bad
const module = {
    isValid: true,
    id: 1234,
    create: () => { doThing() },
    isRunning: false,
    name: "test",
    url: "https://google.com",
    isAvailable: true
}
```

```js
// Good
const module = {
    id: 1234,
    name: "test",
    create: () => { doThing() },
    isAvailable: true,
    isRunning: false,
    isValid: true,
    url: "https://google.com"
}
```

---
_Source: https://npm.io/package/eslint-plugin-sort-keys-custom-order · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
