eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

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

Open ziserman opened this issue 1 year ago • 7 comments

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?

ziserman avatar Mar 06 '24 13:03 ziserman