import-js/eslint-plugin-import

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

Open

#2 976 ouverte le 6 mars 2024

Voir sur GitHub
 (7 commentaires) (2 réactions) (0 assignés)JavaScript (1 540 forks)batch import
enhancementhelp wanted

Métriques du dépôt

Stars
 (4 946 stars)
Métriques de merge PR
 (Merge moyen 138j 22h) (3 PRs mergées en 30 j)

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:

.
├── 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?

Guide contributeur