eslint-plugin-sort
Autofixable sort rules for ESLint.
Installation
npm install -D eslint-plugin-sort
yarn add -D eslint-plugin-sort
Usage
After installing, add sort
to your list of ESLint plugins and extend the recommended configuration. This will enable all available rules as warnings.
{
"extends": ["plugin:sort/recommended"],
"plugins": ["sort"]
}
Rules
While the recommended configuration is the simplest way to use this plugin, you can also configure the rules manually based on your needs.
sort/object-properties
🔧
Sorts object properties alphabetically and case insensitive in ascending order.
Examples of incorrect code for this rule.
var a = { b: 1, c: 2, a: 3 }
var a = { C: 1, b: 2 }
var a = { C: 1, b: { y: 1, x: 2 } }
Examples of correct code for this rule.
var a = { a: 1, b: 2, c: 3 }
var a = { b: 1, C: 2 }
var a = { b: { x: 1, y: 2 }, C: 1 }
sort/destructured-properties
🔧
Sorts properties in object destructuring patterns alphabetically and case insensitive in ascending order.
Examples of incorrect code for this rule.
let { b, c, a } = {}
let { C, b } = {}
let { b: a, a: b } = {}
Examples of correct code for this rule.
let { a, b, c } = {}
let { b, C } = {}
let { a: b, b: a } = {}
sort/imported-variables
🔧
Sorts imported variable names alphabetically and case insensitive in ascending order.
Examples of incorrect code for this rule.
import { b, c, a } from "a"
import { C, b } from "a"
import { b as a, a as b } from "a"
Examples of correct code for this rule.
import { a, b, c } from "a"
import { b, C } from "a"
import { a as b, b as a } from "a"
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!