Gathering detailed insights and metrics for eslint-import-resolver-webpack
Gathering detailed insights and metrics for eslint-import-resolver-webpack
Gathering detailed insights and metrics for eslint-import-resolver-webpack
Gathering detailed insights and metrics for eslint-import-resolver-webpack
eslint-import-resolver-typescript
This plugin adds `TypeScript` support to `eslint-plugin-import`
eslint-import-resolver-node
Node default behavior import resolution plugin for eslint-plugin-import.
eslint-import-resolver-alias
a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias.
eslint-import-resolver-babel-module
babel-plugin-module-resolver resolver for eslint-plugin-import
ESLint plugin with rules that help validate proper imports.
npm install eslint-import-resolver-webpack
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
5,573 Stars
2,292 Commits
1,565 Forks
38 Watching
16 Branches
358 Contributors
Updated on 27 Nov 2024
Minified
Minified + Gzipped
JavaScript (99.01%)
HTML (0.51%)
TypeScript (0.23%)
Shell (0.19%)
PowerShell (0.03%)
Batchfile (0.02%)
Cumulative downloads
Total Downloads
Last day
-1.4%
251,059
Compared to previous day
Last week
7.8%
1,297,738
Compared to previous week
Last month
22.1%
5,049,200
Compared to previous month
Last year
-1.7%
51,931,396
Compared to previous year
10
2
6
This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names. All the goodness that the ES2015+ static module syntax intends to provide, marked up in your editor.
IF YOU ARE USING THIS WITH SUBLIME: see the bottom section for important info.
💼 Configurations enabled in.
⚠️ Configurations set to warn in.
🚫 Configurations disabled in.
❗ Set in the errors
configuration.
☑️ Set in the recommended
configuration.
⌨️ Set in the typescript
configuration.
🚸 Set in the warnings
configuration.
🔧 Automatically fixable by the --fix
CLI option.
💡 Manually fixable by editor suggestions.
❌ Deprecated.
Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | ❌ |
---|---|---|---|---|---|---|---|
export | Forbid any invalid exports, i.e. re-export of the same name. | ❗ ☑️ | |||||
no-deprecated | Forbid imported names marked with @deprecated documentation tag. | ||||||
no-empty-named-blocks | Forbid empty named import blocks. | 🔧 | 💡 | ||||
no-extraneous-dependencies | Forbid the use of extraneous packages. | ||||||
no-mutable-exports | Forbid the use of mutable exports with var or let . | ||||||
no-named-as-default | Forbid use of exported name as identifier of default export. | ☑️ 🚸 | |||||
no-named-as-default-member | Forbid use of exported name as property of default export. | ☑️ 🚸 | |||||
no-unused-modules | Forbid modules without exports, or exports without matching import in another module. |
Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | ❌ |
---|---|---|---|---|---|---|---|
no-amd | Forbid AMD require and define calls. | ||||||
no-commonjs | Forbid CommonJS require calls and module.exports or exports.* . | ||||||
no-import-module-exports | Forbid import statements with CommonJS module.exports. | 🔧 | |||||
no-nodejs-modules | Forbid Node.js builtin modules. | ||||||
unambiguous | Forbid potentially ambiguous parse goal (script vs. module ). |
Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | ❌ |
---|---|---|---|---|---|---|---|
default | Ensure a default export is present, given a default import. | ❗ ☑️ | |||||
named | Ensure named imports correspond to a named export in the remote file. | ❗ ☑️ | ⌨️ | ||||
namespace | Ensure imported namespaces contain dereferenced properties as they are dereferenced. | ❗ ☑️ | |||||
no-absolute-path | Forbid import of modules using absolute paths. | 🔧 | |||||
no-cycle | Forbid a module from importing a module with a dependency path back to itself. | ||||||
no-dynamic-require | Forbid require() calls with expressions. | ||||||
no-internal-modules | Forbid importing the submodules of other modules. | ||||||
no-relative-packages | Forbid importing packages through relative paths. | 🔧 | |||||
no-relative-parent-imports | Forbid importing modules from parent directories. | ||||||
no-restricted-paths | Enforce which files can be imported in a given folder. | ||||||
no-self-import | Forbid a module from importing itself. | ||||||
no-unresolved | Ensure imports point to a file/module that can be resolved. | ❗ ☑️ | |||||
no-useless-path-segments | Forbid unnecessary path segments in import and require statements. | 🔧 | |||||
no-webpack-loader-syntax | Forbid webpack loader syntax in imports. |
Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | ❌ |
---|---|---|---|---|---|---|---|
consistent-type-specifier-style | Enforce or ban the use of inline type-only markers for named imports. | 🔧 | |||||
dynamic-import-chunkname | Enforce a leading comment with the webpackChunkName for dynamic imports. | 💡 | |||||
exports-last | Ensure all exports appear after other statements. | ||||||
extensions | Ensure consistent use of file extension within the import path. | ||||||
first | Ensure all imports appear before other statements. | 🔧 | |||||
group-exports | Prefer named exports to be grouped together in a single export declaration | ||||||
imports-first | Replaced by import/first . | 🔧 | ❌ | ||||
max-dependencies | Enforce the maximum number of dependencies a module can have. | ||||||
newline-after-import | Enforce a newline after import statements. | 🔧 | |||||
no-anonymous-default-export | Forbid anonymous values as default exports. | ||||||
no-default-export | Forbid default exports. | ||||||
no-duplicates | Forbid repeated import of the same module in multiple places. | ☑️ 🚸 | 🔧 | ||||
no-named-default | Forbid named default exports. | ||||||
no-named-export | Forbid named exports. | ||||||
no-namespace | Forbid namespace (a.k.a. "wildcard" * ) imports. | 🔧 | |||||
no-unassigned-import | Forbid unassigned imports | ||||||
order | Enforce a convention in module import order. | 🔧 | |||||
prefer-default-export | Prefer a default export if module exports a single name or multiple names. |
eslint-plugin-import
for enterpriseAvailable as part of the Tidelift Subscription.
The maintainers of eslint-plugin-import
and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
1# inside your project's working tree 2npm install eslint-plugin-import --save-dev
.eslintrc
)All rules are off by default. However, you may extend one of the preset configs, or configure them manually in your .eslintrc.(yml|json|js)
.
1{ 2 "extends": [ 3 "eslint:recommended", 4 "plugin:import/recommended", 5 ], 6}
1{ 2 "rules": { 3 "import/no-unresolved": ["error", { "commonjs": true, "amd": true }] 4 "import/named": "error", 5 "import/namespace": "error", 6 "import/default": "error", 7 "import/export": "error", 8 // etc... 9 }, 10},
eslint.config.js
)All rules are off by default. However, you may configure them manually in your eslint.config.(js|cjs|mjs)
, or extend one of the preset configs:
1import importPlugin from 'eslint-plugin-import'; 2import js from '@eslint/js'; 3 4export default [ 5 js.configs.recommended, 6 importPlugin.flatConfigs.recommended, 7 { 8 files: ['**/*.{js,mjs,cjs}'], 9 languageOptions: { 10 ecmaVersion: 'latest', 11 sourceType: 'module', 12 }, 13 rules: { 14 'no-unused-vars': 'off', 15 'import/no-dynamic-require': 'warn', 16 'import/no-nodejs-modules': 'warn', 17 }, 18 }, 19];
You may use the following snippet or assemble your own config using the granular settings described below it.
Make sure you have installed @typescript-eslint/parser
and eslint-import-resolver-typescript
which are used in the following configuration.
1{ 2 "extends": [ 3 "eslint:recommended", 4 "plugin:import/recommended", 5// the following lines do the trick 6 "plugin:import/typescript", 7 ], 8 "settings": { 9 "import/resolver": { 10 // You will also need to install and configure the TypeScript resolver 11 // See also https://github.com/import-js/eslint-import-resolver-typescript#configuration 12 "typescript": true, 13 "node": true, 14 }, 15 }, 16}
With the advent of module bundlers and the current state of modules and module
syntax specs, it's not always obvious where import x from 'module'
should look
to find the file behind module
.
Up through v0.10ish, this plugin has directly used substack's resolve
plugin,
which implements Node's import behavior. This works pretty well in most cases.
However, webpack allows a number of things in import module source strings that
Node does not, such as loaders (import 'file!./whatever'
) and a number of
aliasing schemes, such as externals
: mapping a module id to a global name at
runtime (allowing some modules to be included more traditionally via script tags).
In the interest of supporting both of these, v0.11 introduces resolvers.
Currently Node and webpack resolution have been implemented, but the resolvers are just npm packages, so third party packages are supported (and encouraged!).
You can reference resolvers in several ways (in order of precedence):
eslint-import-resolver
name, like eslint-import-resolver-foo
:1// .eslintrc 2{ 3 "settings": { 4 // uses 'eslint-import-resolver-foo': 5 "import/resolver": "foo", 6 }, 7}
1# .eslintrc.yml 2settings: 3 # uses 'eslint-import-resolver-foo': 4 import/resolver: foo
1// .eslintrc.js 2module.exports = { 3 settings: { 4 'import/resolver': { 5 foo: { someConfig: value } 6 } 7 } 8}
my-awesome-npm-module
:1// .eslintrc 2{ 3 "settings": { 4 "import/resolver": "my-awesome-npm-module", 5 }, 6}
1# .eslintrc.yml 2settings: 3 import/resolver: 'my-awesome-npm-module'
1// .eslintrc.js 2module.exports = { 3 settings: { 4 'import/resolver': { 5 'my-awesome-npm-module': { someConfig: value } 6 } 7 } 8}
computed property
name:1// .eslintrc.js 2module.exports = { 3 settings: { 4 'import/resolver': { 5 [path.resolve('../../../my-resolver')]: { someConfig: value } 6 } 7 } 8}
Relative paths will be resolved relative to the source's nearest package.json
or
the process's current working directory if no package.json
is found.
If you are interesting in writing a resolver, see the spec for more details.
You may set the following settings in your .eslintrc
:
import/extensions
A list of file extensions that will be parsed as modules and inspected for
export
s.
This defaults to ['.js']
, unless you are using the react
shared config,
in which case it is specified as ['.js', '.jsx']
. Despite the default,
if you are using TypeScript (without the plugin:import/typescript
config
described above) you must specify the new extensions (.ts
, and also .tsx
if using React).
1"settings": { 2 "import/extensions": [ 3 ".js", 4 ".jsx" 5 ] 6}
If you require more granular extension definitions, you can use:
1"settings": { 2 "import/resolver": { 3 "node": { 4 "extensions": [ 5 ".js", 6 ".jsx" 7 ] 8 } 9 } 10}
Note that this is different from (and likely a subset of) any import/resolver
extensions settings, which may include .json
, .coffee
, etc. which will still
factor into the no-unresolved
rule.
Also, the following import/ignore
patterns will overrule this list.
import/ignore
A list of regex strings that, if matched by a path, will
not report the matching module if no export
s are found.
In practice, this means rules other than no-unresolved
will not report on any
import
s with (absolute filesystem) paths matching this pattern.
no-unresolved
has its own ignore
setting.
1{ 2 "settings": { 3 "import/ignore": [ 4 "\.coffee$", // fraught with parse errors 5 "\.(scss|less|css)$", // can't parse unprocessed CSS modules, either 6 ], 7 }, 8}
import/core-modules
An array of additional modules to consider as "core" modules--modules that should
be considered resolved but have no path on the filesystem. Your resolver may
already define some of these (for example, the Node resolver knows about fs
and
path
), so you need not redefine those.
For example, Electron exposes an electron
module:
1import 'electron' // without extra config, will be flagged as unresolved!
that would otherwise be unresolved. To avoid this, you may provide electron
as a
core module:
1// .eslintrc 2{ 3 "settings": { 4 "import/core-modules": ["electron"], 5 }, 6}
In Electron's specific case, there is a shared config named electron
that specifies this for you.
Contribution of more such shared configs for other platforms are welcome!
import/external-module-folders
An array of folders. Resolved modules only from those folders will be considered as "external". By default - ["node_modules"]
. Makes sense if you have configured your path or webpack to handle your internal paths differently and want to consider modules from some folders, for example bower_components
or jspm_modules
, as "external".
This option is also useful in a monorepo setup: list here all directories that contain monorepo's packages and they will be treated as external ones no matter which resolver is used.
If you are using yarn
PnP as your package manager, add the .yarn
folder and all your installed dependencies will be considered as external
, instead of internal
.
Each item in this array is either a folder's name, its subpath, or its absolute prefix path:
jspm_modules
will match any file or folder named jspm_modules
or which has a direct or non-direct parent named jspm_modules
, e.g. /home/me/project/jspm_modules
or /home/me/project/jspm_modules/some-pkg/index.js
.
packages/core
will match any path that contains these two segments, for example /home/me/project/packages/core/src/utils.js
.
/home/me/project/packages
will only match files and directories inside this directory, and the directory itself.
Please note that incomplete names are not allowed here so components
won't match bower_components
and packages/ui
won't match packages/ui-utils
(but will match packages/ui/utils
).
import/parsers
A map from parsers to file extension arrays. If a file extension is matched, the dependency parser will require and use the map key as the parser instead of the configured ESLint parser. This is useful if you're inter-op-ing with TypeScript directly using webpack, for example:
1// .eslintrc 2{ 3 "settings": { 4 "import/parsers": { 5 "@typescript-eslint/parser": [".ts", ".tsx"], 6 }, 7 }, 8}
In this case, @typescript-eslint/parser
must be installed and require-able from the running eslint
module's location
(i.e., install it as a peer of ESLint).
This is currently only tested with @typescript-eslint/parser
(and its predecessor,
typescript-eslint-parser
) but should theoretically work with any moderately
ESTree-compliant parser.
It's difficult to say how well various plugin features will be supported, too,
depending on how far down the rabbit hole goes. Submit an issue if you find strange
behavior beyond here, but steel your heart against the likely outcome of closing
with wontfix
.
import/resolver
See resolvers.
import/cache
Settings for cache behavior. Memoization is used at various levels to avoid the copious amount of fs.statSync
/module parse calls required to correctly report errors.
For normal eslint
console runs, the cache lifetime is irrelevant, as we can strongly assume that files should not be changing during the lifetime of the linter process (and thus, the cache in memory)
For long-lasting processes, like eslint_d
or eslint-loader
, however, it's important that there be some notion of staleness.
If you never use eslint_d
or eslint-loader
, you may set the cache lifetime to Infinity
and everything should be fine:
1// .eslintrc 2{ 3 "settings": { 4 "import/cache": { 5 "lifetime": "∞", // or Infinity, in a JS config 6 }, 7 }, 8}
Otherwise, set some integer, and cache entries will be evicted after that many seconds have elapsed:
1// .eslintrc 2{ 3 "settings": { 4 "import/cache": { 5 "lifetime": 5, // 30 is the default 6 }, 7 }, 8}
import/internal-regex
A regex for packages should be treated as internal. Useful when you are utilizing a monorepo setup or developing a set of packages that depend on each other.
By default, any package referenced from import/external-module-folders
will be considered as "external", including packages in a monorepo like yarn workspace or lerna environment. If you want to mark these packages as "internal" this will be useful.
For example, if your packages in a monorepo are all in @scope
, you can configure import/internal-regex
like this
1// .eslintrc 2{ 3 "settings": { 4 "import/internal-regex": "^@scope/", 5 }, 6}
SublimeLinter-eslint introduced a change to support .eslintignore
files
which altered the way file paths are passed to ESLint when linting during editing.
This change sends a relative path instead of the absolute path to the file (as ESLint
normally provides), which can make it impossible for this plugin to resolve dependencies
on the filesystem.
This workaround should no longer be necessary with the release of ESLint 2.0, when
.eslintignore
will be updated to work more like a .gitignore
, which should
support proper ignoring of absolute paths via --stdin-filename
.
In the meantime, see roadhump/SublimeLinter-eslint#58
for more details and discussion, but essentially, you may find you need to add the following
SublimeLinter
config to your Sublime project file:
1{ 2 "folders": 3 [ 4 { 5 "path": "code" 6 } 7 ], 8 "SublimeLinter": 9 { 10 "linters": 11 { 12 "eslint": 13 { 14 "chdir": "${project}/code" 15 } 16 } 17 } 18}
Note that ${project}/code
matches the code
provided at folders[0].path
.
The purpose of the chdir
setting, in this case, is to set the working directory
from which ESLint is executed to be the same as the directory on which SublimeLinter-eslint
bases the relative path it provides.
See the SublimeLinter docs on chdir
for more information, in case this does not work with your project.
If you are not using .eslintignore
, or don't have a Sublime project file, you can also
do the following via a .sublimelinterrc
file in some ancestor directory of your
code:
1{ 2 "linters": { 3 "eslint": { 4 "args": ["--stdin-filename", "@"] 5 } 6 } 7}
I also found that I needed to set rc_search_limit
to null
, which removes the file
hierarchy search limit when looking up the directory tree for .sublimelinterrc
:
In Package Settings / SublimeLinter / User Settings:
1{ 2 "user": { 3 "rc_search_limit": null 4 } 5}
I believe this defaults to 3
, so you may not need to alter it depending on your
project folder max depth.
No vulnerabilities found.
Reason
26 commit(s) and 22 issue activity found in the last 90 days -- score normalized to 10
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 14/24 approved changesets -- score normalized to 5
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More