Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint-plugin-import rule import/no-unused-modules does not work with vscode-eslint. #717

Closed
ehmicky opened this issue Jul 18, 2019 · 9 comments
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities *out-of-scope Posted issue is not in scope of VS Code

Comments

@ehmicky
Copy link

ehmicky commented Jul 18, 2019

The plugin eslint-plugin-import has a rule import/no-unused-modules that checks (among other things) for exports that are not used in other files.

"import/no-unused-modules": [2, {"unusedExports": true}]

This does not work well with vscode-eslint: files that have not been opened in the editor yet are not taken into account. As a consequence exports are being reported as unused even though they are used.

For example, if I just open a new VSCode Window:

Screenshot from 2019-07-18 12-43-27

The serialize() exported function is reported, even after saving the file.

Now if I open that other file which imports the serialize() function:

Screenshot from 2019-07-18 12-44-04

Then go back to the first file and save it, the reporting is now gone:

Screenshot from 2019-07-18 12-44-11

It seems like only files that are open within VSCode are considered for the import/no-unused-modules rule.

This behavior only seems to happen with VSCode. If I run eslint on the command line, everything works fine.

I've initially opened an issue with eslint-plugin-import but got redirected here by its author.

VSCode: 1.36.1
vscode-eslint: 1.9.0
OS: Ubuntu 19.04
ESLint: 6.0.1
eslint-plugin-import: 2.18.0
Node: 12.6.0

@dbaeumer
Copy link
Member

dbaeumer commented Aug 7, 2019

@ehmicky ESLint only validates the open files. This is comparable to running eslint in the terminal for a single file. E.g. eslint folder/file.js. If you do this are the exports reported as well?

There is also a eslint validate task that validates the whole project. It can be enable with "eslint.provideLintTask": true. You can invoke the task using Run Task from the Terminal menu.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Aug 7, 2019
@ehmicky
Copy link
Author

ehmicky commented Aug 7, 2019

@dbaeumer thanks for looking into this.

If I understand you correctly, VSCode-ESLint only validates the opened files. This might be an issue with rules like no-unused-modules where linting needs to happen project-wise and not file-wise.

Doing eslint folder/file.js works (i.e. the exports are not reported) because that ESLint rule receives a src option (defaulting to current directory) and manually recurse over it to find out which files are depending on folder/file.js. At least that's what I think the rule does under the hood, I am not completely sure (source code). It just works (outside of VSCode-ESLint).

The eslint.provideLintTask would unfortunately require an explicit action to be triggered, as opposed to linting in realtime.

@dbaeumer
Copy link
Member

dbaeumer commented Aug 8, 2019

@ehmicky thanks for the additional information. The problem is that we can't do that on typing since it would not scale parsing all files in a workspace.

What would work is that we auto trigger the lint task on save so that there is not need for a user interaction.

@dbaeumer dbaeumer added feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster labels Aug 8, 2019
@dbaeumer dbaeumer added this to the On Deck milestone Aug 8, 2019
@dbaeumer dbaeumer added the help wanted Issues identified as good community contribution opportunities label Aug 8, 2019
@dbaeumer
Copy link
Member

dbaeumer commented Aug 8, 2019

Good opportunity for a PR.

@ehmicky
Copy link
Author

ehmicky commented Aug 8, 2019

@dbaeumer yes triggering the lint task on save would work for me, thanks!

@dbaeumer dbaeumer modified the milestones: On Deck, Backlog Oct 24, 2019
@dbaeumer dbaeumer added the *out-of-scope Posted issue is not in scope of VS Code label Oct 26, 2020
@vscodebot
Copy link

vscodebot bot commented Oct 26, 2020

We closed this issue because we don't plan to address it in the foreseeable future. You can find more detailed information about our decision-making process here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding and happy coding!

@vscodebot vscodebot bot closed this as completed Oct 26, 2020
@dbaeumer
Copy link
Member

I am still happy to accept a PR if someone wants to work on this.

@Axedyson
Copy link

Axedyson commented Sep 23, 2021

I get the same error would love to see a PR!

@adamsuskin
Copy link

adamsuskin commented Mar 30, 2022

I am seeing this issue manifest with two open files. ESLint on the command-line works fine.

VSCode: 1.65.2
vscode-eslint: 2.2.2
OS: macOS Monterey 12.3
ESLint: 8.4.1
eslint-plugin-import: 2.25.4
Node: 16.14.0

The server trace logs appear to show only producing a notification that the unused module correction is fixed when the server is restarted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

4 participants