eslint-plugin-module-imports
ESLint plugin for ES6 style module imports
Configurable ESLint rules to group and sort ES6 style module imports, require
imports are not supported.
In contrast to eslint-plugin-import, this plugin doesn't attempt to actually resolve the imports.
Install
npm install --save-dev eslint-plugin-module-imports
Usage
In your .eslintrc
:
Rules
module-imports/group
Requires imports to be grouped and groups to be separated by a new line. Auto-fixable!
The following configuration options can be set:
where string
can be a package name, a scope name or one of the following tokens:
#NODE
: all node builtin packages likefs
andpath
#EXTERNAL
: all other declared dependencies, e.g.lodash
,react
, etc.#RELATIVE
: all relative imports#ABSOLUTE
: all absolute imports, never seen a project use these, but it's possible
The default configuration is:
Nested arrays allow packages to be treated as a single group, e.g.
Explicitly declared packages and scopes have precedence over the predefined tokens. Unused tokens are in an implicit additional group.
module-imports/sort
Requires import groups to be sorted by module first and then by specifier. Auto-fixable!
The following configuration options can be set:
specifier
: determines specifier priority, e.g. inimport { foo as bar } from 'baz'
foo
is'source'
andbar
is'rename'
caseGroups
: whentrue
, import names need to be grouped by case before sortingsortExports
: whether to sort deferred export groups, i.e. all statements that export from another module
For all other possible settings, see String#localeCompare.
The default configuration is: