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:

The serialize() exported function is reported, even after saving the file.
Now if I open that other file which imports the serialize() function:

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

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
@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 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.
@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.
Good opportunity for a PR.
@dbaeumer yes triggering the lint task on save would work for me, thanks!
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!
I am still happy to accept a PR if someone wants to work on this.
Most helpful comment
@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.