包详细信息

eslint-plugin-import-sorting

stormwarning9062.2.0

ESLint plugin to group and sort imports by module, à la Python isort

eslint, eslint-plugin, eslintplugin, import

自述文件

eslint-plugin-import-sorting

Enforce a convention in the order of import statements, inspired by isort’s grouping style:

  1. Node standard modules
  2. Framework modules
  3. External modules
  4. Internal modules
  5. Explicitly local modules

This plugin includes an additional group for “style” imports where the import source ends in .css or other style format. Imports are sorted alphabetically, except for local modules, which are sorted by the number of . segements in the path first, then alphabetically.

Usage

Install the plugin, and ESLint if it is not already.

npm install --save-dev eslint eslint-plugin-import-sorting

Include the plugin in the plugins key of your ESLint config and enable the rules.

// eslint.config.js

import importSortingPlugin from 'eslint-plugin-import-sorting'

export default [
    {
        plugins: {
            'import-sorting': importSortingPlugin,
        },
        rules: {
            'import-sorting/order': 'error',
        },
    },
]

🔧 Automatically fixable by the --fix CLI option.

Name Description 🔧
order Consistently order import statements. 🔧
specifier-order Consistently order named import specifiers. 🔧

更新日志

eslint-plugin-import-sorting

2.2.0

Minor Changes

  • Explicitly set case sensitivity & sort uppercase before lowercase (#31)

Patch Changes

  • Fix semicolons being added to end of import specifiers after sorting (#29)

2.1.1

Patch Changes

  • Fix bug with grouping when settings are not explicitly defined (#27)

2.1.0

Minor Changes

  • Add new specifier-order rule for sorting named imports (#25)

2.0.0

Major Changes

  • Remove deprecated settings (#18)

    • import-sorting/known-framework should be changed to import-sorting/framework-patterns
    • import-sorting/known-first-party should be changed to import-sorting/internal-patterns

Minor Changes

  • Group unassigned imports at the top (#18) Unassigned imports are grouped together, but not sorted in case of potential side-effects.
  • Include Bun runtime modules in builtin group (#18) Since some builtin modules require a bun: or node: protocol prefix while others do not, sorting ignores the protocol prefix. (Including it consistently is recommended)
  • Include additional extensions in style group (#18) The style group now matches imports of Less, Sass, Stylus, and more.

1.2.2

Patch Changes

  • Export ESM and types (#21) Plugin is exported as ESM and CJS, and includes type declarations as well.

1.2.1

Patch Changes

  • Deprecate plugin settings (#19) The next major version of the plugin will use

    • import-sorting/framework-patterns instead of known-framework
    • import-sorting/internal-patterns instead of known-first-party

1.2.0

Minor Changes

  • Allow array values for plugin settings (#14) Settings options now accept an array of pattern strings, instead of only a single, more convoluted, RegExp string. Closes #8

1.1.0

Minor Changes

  • Sort numerals in path strings naturally (#11) Now ensures that 10 will sort after 2, for example.

Patch Changes

  • Fix local import sort order when dot segment count is the same (#11) Sorting will now take the entire path into account, instead of just the basename of the path.
  • Add engines key to indicate minimum Node version (#12)

1.0.3

Patch Changes

  • Fix error when plugin settings are undefined (#9)

1.0.2

Patch Changes

  • Update export and build strategy (#6)

    Should fix issues with plugin being unable to load, or rule definitions not being found.

1.0.1

Patch Changes

1.0.0

Major Changes