no-unused-modules: ignore imports in files listed in ignoreExports
#2976 aperta il 6 mar 2024
Metriche repository
- Star
- (4946 star)
- Metriche merge PR
- (Merge medio 138g 22h) (3 PR mergiate in 30 g)
Descrizione
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:
.
├── 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:
// .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?