eslint-plugin-sort
raw JSON → 4.0.0 verified Sat Apr 25 auth: no javascript
Auto-fixable sort rules for ESLint. Current stable version is 4.0.0 (October 2024), released with semantic versioning and a monthly release cadence. Key differentiators include native TypeScript support, recommended configuration, support for both flat and legacy ESLint configs, and rules that sort imports, exports, destructuring, object properties, type properties, string enums, and string unions with auto-fix. Compared to alternatives like eslint-plugin-import/order, it offers a narrower focus on sorting with simpler configuration.
Common errors
error Error: Failed to load plugin 'sort': Cannot find module 'eslint-plugin-sort' ↓
cause Missing plugin installation or incorrect import path
fix
Run
npm install -D eslint-plugin-sort and ensure the import is correct error Error: ESLint configuration error: [plugin 'sort'] requires eslint >=8.56.0 ↓
cause Outdated ESLint version incompatible with plugin v4
fix
Upgrade ESLint to >=8.56.0
error TypeError: sort.configs is not iterable ↓
cause Using sort.configs incorrectly in flat config
fix
Use spread operator:
export default [...sort.configs['flat/recommended'], ...] Warnings
breaking v4.0.0 drops support for ESLint < 8.56.0 ↓
fix Upgrade ESLint to >=8.56.0
breaking v3.0.0 drops support for ESLint < 8 ↓
fix Upgrade ESLint to >=8
gotcha Flat config requires v2.11.0 or later ↓
fix Upgrade to v2.11.0+ or use legacy config
gotcha The recommended config enables rules as warnings by default ↓
fix Override rule severity to 'error' or 'off' as needed
deprecated The 'sort/imports' rule's 'groups' option changed in v3; previously used different default groups ↓
fix Review migration guide for new default groups
Install
npm install eslint-plugin-sort yarn add eslint-plugin-sort pnpm add eslint-plugin-sort Imports
- default import wrong
const sort = require('eslint-plugin-sort');correctimport sort from 'eslint-plugin-sort' - flat config
import sort from 'eslint-plugin-sort'; export default [...sort.configs['flat/recommended']]; - rules wrong
require('eslint-plugin-sort').rulescorrectimport sort from 'eslint-plugin-sort'; sort.configs['flat/recommended'].rules
Quickstart
import sort from 'eslint-plugin-sort';
export default [
sort.configs['flat/recommended'],
{
rules: {
'sort/imports': ['error', { groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'] }],
'sort/export-members': 'warn',
},
},
];