eslint-plugin-sort-export-all

raw JSON →
2.1.0 verified Sat Apr 25 auth: no javascript

ESLint plugin providing a rule to sort re-export statements (export * from ...) with autofix support. Current stable version is 2.1.0, released with no breaking changes from 2.0.0. It ships TypeScript type definitions and requires ESLint as a peer dependency. Key differentiator: specifically targets sorting of `export *` (also known as star exports) in JavaScript/TypeScript modules, offering automatic sorting via ESLint's fix mechanism. Unlike general import sorting plugins, this one focuses exclusively on re-exports, making it lightweight and purpose-built for monorepos or projects that rely heavily on barrel files.

error Error: Cannot find module 'eslint-plugin-sort-export-all/config'
cause Mistakenly trying to require() the config sub-path in a CommonJS context.
fix
Use dynamic import or switch to ESM: const sortExportAllConfig = (await import('eslint-plugin-sort-export-all/config')).default;
error ESLint: Configuration for rule "sort-export-all/sort-export-all" is invalid. Value "error" should be string.
cause Rule configured with a severity number or object instead of a string like 'error' or 'warn'.
fix
Use rule: 'sort-export-all/sort-export-all': 'warn' or ['warn', { ...options }].
error TypeError: eslintPluginSortExportAll is not a function
cause Using require('eslint-plugin-sort-export-all') in CJS without .default.
fix
Use const eslintPluginSortExportAll = require('eslint-plugin-sort-export-all').default; or switch to ESM import.
error ESLint couldn't find the plugin "sort-export-all".
cause Plugin key in flat config is misspelled or not correctly registered under plugins object.
fix
Ensure plugins: { 'sort-export-all': eslintPluginSortExportAll } exactly as shown.
breaking The plugin uses ESM-only exports and does not provide a CommonJS build. Projects using ESLint with require() in .eslintrc or CJS config will fail.
fix Upgrade to ESLint 9 flat config and use import syntax. Alternatively, stick with version 1.x if CJS is required.
gotcha The rule 'sort-export-all/sort-export-all' must be enabled with severity 'warn' or 'error'. The 'off' severity does nothing and no fix is applied.
fix Set rule to 'warn' or 'error' to enable autofix.
gotcha The plugin only sorts export * statements. Named exports like export { a, b } or export default are not affected. Users may expect broader sorting.
fix Use other ESLint plugins like eslint-plugin-simple-import-sort for named exports.
gotcha Autofix may conflict with other ESLint rules that also modify import/export statements (e.g., eslint-plugin-import). Run the plugin as the last step or disable conflicting autofixes.
fix Configure ESLint to run this rule's fix separately, or use --fix-type suggestion to control fix order.
npm install eslint-plugin-sort-export-all
yarn add eslint-plugin-sort-export-all
pnpm add eslint-plugin-sort-export-all

Shows ESLint flat config setup using the provided config helper or manual plugin registration, with an example of how the rule sorts star exports.

// eslint.config.js
import sortExportAllConfig from 'eslint-plugin-sort-export-all/config';

export default [
  sortExportAllConfig(),
  // additional config...
];

// Or manually:
import eslintPluginSortExportAll from 'eslint-plugin-sort-export-all';

export default [
  {
    plugins: {
      'sort-export-all': eslintPluginSortExportAll,
    },
    rules: {
      'sort-export-all/sort-export-all': 'warn',
    },
  },
];

// Example file that will be fixed:
// input: export * from 'c'; export * from 'a';
// output: export * from 'a'; export * from 'c';