Package Exports
- eslint-plugin-sort-properties
- eslint-plugin-sort-properties/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eslint-plugin-sort-properties) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
eslint-plugin-sort-properties
This plugin provides rules that enforce the sorting of properties in object expressions, object destructuring, type literals, and interface members.
Inspired by eslint-plugin-sort-keys-fix, it is designed to be auto-fixable but way faster.
Additionally, inspired by the eslint-plugin-react/jsx-sort-props rule, it supports giving higher priority to function properties when sorting.
⚠️ Configurations set to warn in.
🌐 Set in the all configuration.
🔧 Automatically fixable by the --fix CLI option.
💡 Manually fixable by editor suggestions.
| Name | Description | ⚠️ | 🔧 | 💡 |
|---|---|---|---|---|
| sort-interface | Enforce interface members to be sorted. | 🌐 | 🔧 | 💡 |
| sort-object-destructing | Enforce properties in object destructuring to be sorted. | 🌐 | 🔧 | 💡 |
| sort-object-expression | Enforce properties in object expressions to be sorted. | 🌐 | 🔧 | 💡 |
| sort-type-literal | Enforce properties in type literals to be sorted. | 🌐 | 🔧 | 💡 |
Installation
You'll first need to install ESLint:
$ npm install eslint --save-devNext, install eslint-plugin-sort-properties:
$ npm install eslint-plugin-sort-properties --save-devConfiguration (legacy: .eslintrc*)
⚠️ Important note
To use rules for typescript(sort-interface,sort-type-literal), you need to specify the parser as@typescript-eslint/parser.
module.exports = {
// ...
overrides: [
{
files: ["*.{ts,tsx}"],
parser: "@typescript-eslint/parser",
},
],
};Use all to enable all rules. Here's an example configuration in your .eslintrc:
module.exports = {
extends: ["plugin:sort-properties/all"],
};or you can enable specific rules:
module.exports = {
plugins: ["sort-properties"],
rules: {
"sort-properties/sort-interface": "warn",
"sort-properties/sort-object-destructing": "warn",
"sort-properties/sort-object-expression": "warn",
"sort-properties/sort-type-literal": "warn",
},
};Configuration (new: eslint.config.js)
⚠️ Important note
To use rules for typescript(sort-interface,sort-type-literal), you need to specify the parser as@typescript-eslint/parser.
const tseslint = require("typescript-eslint");
// Use utility function for typescript-eslint
module.exports = tseslint.config(
{ ... }
);
// Or manually specify the parser
module.exports = [
{
files: ["*.{ts,tsx}"],
languageOptions: {
parser: tseslint.parser,
},
},
];Use flatAll to enable all rules. Here's an example configuration in your eslint.config.js:
const sortPropertiesPlugin = require("eslint-plugin-sort-properties");
module.exports = [
// ...
sortPropertiesPlugin.configs.flatAll,
];or you can enable specific rules:
module.exports = [
// ...
{
plugins: {
"sort-properties": require("eslint-plugin-sort-properties"),
},
rules: {
"sort-properties/sort-interface": "warn",
"sort-properties/sort-object-destructing": "warn",
"sort-properties/sort-object-expression": "warn",
"sort-properties/sort-type-literal": "warn",
},
},
];