import-js / import-js/eslint-plugin-import

no-unused-modules: ignore imports in files listed in ignoreExports

Open
#2,976 7 comments 2 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Hello,

I've faced with a problem that it's impossible to warn about unused modules in case the module has imports only to test files, for instance.

**Example**

Suppose, we have a simple file structure like:
```plain
.
├── src/
│ └── do-something/
│ ├── do-something.js
│ └── do-something.test.js
└── .eslintrc.js
```
`do-something.js` imported only inside `do-something.test.js` for tests, obviously.

At the same time files with name `*.test.js` are ignored by `import/no-unused-modules` rule in .eslintrc.js:
```js
// .eslintrc.js
module.exports = {
...
settings: {
"import/extensions": [".js"]
},
plugins: ['import'],
rules: {
'import/no-unused-modules': [
2,
{
src: ['src'],
unusedExports: true,
ignoreExports: ['**/*.test.js'],
},
],
},
}
```

Finally, `do-something.js` has no imports anywhere, except in ignored file with tests of itself. So, it's better to delete `do-something.js` file and everything related to it.

Is there any way to do something like that in the current version?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the example with .eslintrc.js, src/do-something/do-something.js, and src/do-something/do-something.test.js, focusing on the import/no-unused-modules rule and its ignoreExports setting. Trace how imports from ignored files affect unused-module reporting. Done means the source module is reported as unused when its only import is from an ignored test file, with tests covering this configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.