eslint-plugin-module-imports v0.0.8
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
:
{
"plugins": ["module-imports"],
"rules": {
"module-imports/group": "error"
}
}
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:
interface Configuration {
groups?: Array<string | string[]>;
}
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:
{
"groups": ["#NODE", "#EXTERNAL", "#ABSOLUTE", "#RELATIVE"]
}
Nested arrays allow packages to be treated as a single group, e.g.
{
"groups": [["#NODE", "#EXTERNAL"], ["@my-scope", "my-package"], "#RELATIVE"]
}
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:
interface Configuration {
specifier?: 'source' | 'rename';
locales?: string[];
sensitivity?: 'base' | 'accent' | 'case' | 'variant';
ignorePunctuation?: boolean;
numeric?: boolean;
caseFirst?: 'upper' | 'lower' | 'false';
caseGroups?: boolean;
sortExports?: boolean;
}
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:
{
"specifier": "source",
"locales": ["en-US"],
"sensitivity": "variant",
"ignorePunctuation": false,
"numeric": true,
"caseFirst": "lower",
"caseGroups": false,
"sortExports": true
}