Open nnmrts opened 7 months ago
Given that eslint's FlatCompat allows people to use this plugin before it actually supports flat config, I agree adding a note in the readme (linked to from the no-unused-modules docs) here would be good.
I'm not using the no-unused-modules
rule directly, but I am attempting to bundle my ESLint flat config that includes eslint-plugin-import
using rollup.
Of all the plugins & rules I'm using, no-unused-modules
is the only one that's giving me trouble:
(!) Plugin node-resolve: Could not resolve import "eslint/lib/cli-engine/file-enumerator" in /Users/jzwartepoorte/Projects/components/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js using exports defined in /Users/jzwartepoorte/Projects/components/node_modules/eslint/package.json.
(!) Plugin node-resolve: Could not resolve import "eslint/lib/util/glob-utils" in /Users/jzwartepoorte/Projects/components/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js using exports defined in /Users/jzwartepoorte/Projects/components/node_modules/eslint/package.json.
(!) Plugin node-resolve: Could not resolve import "eslint/lib/util/glob-util" in /Users/jzwartepoorte/Projects/components/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js using exports defined in /Users/jzwartepoorte/Projects/components/node_modules/eslint/package.json.
My next step is trying to exclude this rule somehow from bundling.
I’m not sure why you’d ever want to bundle an eslint config - and either way, this plugin requires everything to exist on disk to work properly, so it’s not going to work with that approach.
I'm trying to create a zero dependency ESLint config, which hopefully speeds up ESLint's running time significantly.
As far as I can tell, the paths that node-resolve complains about don't exist?!
That seems like a really bizarre way to solve it; I'd suggest using jest-eslint-runner instead, it does the job without violating the expectations of basically every package.
It seems like the error is coming from your rollup setup - the paths don't necessarily exist, which is why they're being conditionally required in the first place.
For anyone else landing here looking for a solution, here's my eslint.config.cjs
, which works for me :)
const pluginImport = require('eslint-plugin-import');
module.exports = [
{
plugins: {
import: { rules: pluginImport.rules },
},
rules: {
'import/order': 'error',
'import/group-exports': 'error',
'import/exports-last': 'error',
},
},
// ... all your other other configurations
];
@lgenzelis that doesn't solve the problem, as trying to use import/no-unused-modules
still results in a "broken" config.
Given that eslint's FlatCompat allows people to use this plugin before it actually supports flat config, I agree adding a note in the readme (linked to from the no-unused-modules docs) here would be good.
@ljharb any idea how to get this working with the compat? I've been trying various approaches (both with @eslint/eslintrc
and @eslint/compat
) and can't seem to get anything to work.
At this point I don't care how ugly my config gets as long as I can get this rule enabled 😭
is missingExports
also not supported or only unusedExports
?
I think for most users of this plugin it's not immediately obvious that flat configs are not or only partially supported. See for example the mentions of this issue in various commits, PRs and issues: https://github.com/import-js/eslint-plugin-import/issues/2556.
If I understand correctly after going through some of the issues here, the flat config format in general is not "officially" supported by this plugin, however it's not clear to me what exactly breaks and what not. I only found this (which aims to add support but doesn't have a lot of information) and this comment here:
In my opinion it should be made clear somewhere in the readme what "we do not support flat config" actually means. For me personally at least everything except for setting
unusedExports
totrue
inno-unused-modules
"works" though.Which brings me to the main point of this issue: Can we document this fact in https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unused-modules.md? Especially because both the "In the future, these options will be enabled by default (see https://github.com/import-js/eslint-plugin-import/issues/1324)" and the example below might encourage readers to set
unusedExports
totrue
. Maybe a link to https://github.com/import-js/eslint-plugin-import/issues/2907 should be included.