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.

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'], ...]
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
npm install eslint-plugin-sort
yarn add eslint-plugin-sort
pnpm add eslint-plugin-sort

Setup ESLint flat config with eslint-plugin-sort, enabling recommended rules and customizing import sorting groups.

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',
    },
  },
];