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

No error report in editor on "unused-imports/no-unused-imports" #1767

Open
AlexMarlow25 opened this issue Jan 18, 2024 · 9 comments
Open

No error report in editor on "unused-imports/no-unused-imports" #1767

AlexMarlow25 opened this issue Jan 18, 2024 · 9 comments
Labels
info-needed Issue requires more information from poster

Comments

@AlexMarlow25
Copy link

Hi! Unfortunately, plugin is not showing and not fixing errors in editor for "unused-imports/no-unused-imports" rule.
If I run npm script "eslint .", I will see these errors in a terminal. Also, I can see these errors in WebStorm IDE, but not in VS Code.

  • VS Code editor:
Screenshot 2024-01-18 at 19 12 18
  • terminal output:
Screenshot 2024-01-18 at 19 09 55
  • WebStorm:
Screenshot 2024-01-18 at 19 13 23
@dbaeumer
Copy link
Member

@AlexMarlow25 you very likely need to let ESLint know about working directories using eslint.workingDirectories setting.

If this doesn't help, please provide me with a GitHub repository I can clone that demos what you are seeing.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Jan 22, 2024
@AlexMarlow25
Copy link
Author

@AlexMarlow25 you very likely need to let ESLint know about working directories using eslint.workingDirectories setting.

If this doesn't help, please provide me with a GitHub repository I can clone that demos what you are seeing.

Sorry for a long response. Let me clear - ESLint works well in VSCode except these types of rules, which I described (unused-imports/***). I've tried to configure eslint.workingDirectories in these ways:

  • "eslint.workingDirectories": ["./"]
  • "eslint.workingDirectories": [{"mode": "auto"}]
    None of it helps. I will try to make a repo with all of my ESLint plugins and settings, thanks!

@AlexMarlow25
Copy link
Author

AlexMarlow25 commented Mar 7, 2024

@AlexMarlow25 you very likely need to let ESLint know about working directories using eslint.workingDirectories setting.

If this doesn't help, please provide me with a GitHub repository I can clone that demos what you are seeing.

I think I've found a problem! I inspected my config with npx eslint --print-config eslint.config.js and found out, that there two rules:

"ts/no-unused-vars": [
      0
 ],

and

"unused-imports/no-unused-vars": [
      2,
      {
        "args": "after-used",
        "argsIgnorePattern": "^_",
        "vars": "all",
        "varsIgnorePattern": "^_"
      }
],

In result I don't have errors on unused imported variables, as described earlier. But finally I will see them, if I set this rule manually in config to

'ts/no-unused-vars': [
        2,
        {
          args: 'after-used',
          argsIgnorePattern: '^_',
          vars: 'all',
          varsIgnorePattern: '^_',
        },
],

From that moment I think, that a problem somewhere on a WebStorm side 😅 Or I am completely confused.

@yunsii
Copy link

yunsii commented Mar 13, 2024

I have encounterd the same problem, for example: https://github.com/yunsii/cf-worker-status-page-pro/blob/32f076f16843025d06e6223b379f0eceb3447f8b/scripts/public-assets.ts#L3

If I add a extra import chalk from zx:

import { chalk, fs, path } from 'zx'

VS Code report no error, but npm run lint throw an error like:

/home/my/project/cf-worker-status-page-pro/scripts/public-assets.ts
  3:10  error  'chalk' is defined but never used  unused-imports/no-unused-imports

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

@dbaeumer
Copy link
Member

@yunsii can you please provide me with a GitHub repository I can clone with a minimal repro case. Otherwise it is hard to say why it is not working.

@yunsii
Copy link

yunsii commented Mar 14, 2024

Okey, I will try to create a minimal repro later.

@yunsii
Copy link

yunsii commented Mar 14, 2024

@dbaeumer It's really strange:

After my deep investiagtion, it seems that there is a difference between eslint cli and vscode-eslint. Specifically, npx eslint ./hello.ts will throw 2 errors:

/home/projects/vscode-eslint-1767/hello.ts
  1:10  error  'chalk' is defined but never used                                                  unused-imports/no-unused-imports
  3:7   error  'result' is assigned a value but never used. Allowed unused vars must match /^_/u  unused-imports/no-unused-vars

✖ 2 problems (2 errors, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

But there is only 1 error in editor:

image

@AlexMarlow25
Copy link
Author

AlexMarlow25 commented Mar 14, 2024

@yunsii thank you for your repo! In the antfu-eslint-config branch I see the error in the WebStorm too, and don't in VSCode. I've decided to investigate what is going on inside antfu config and found this:

isInEditor = !!((import_node_process3.default.env.VSCODE_PID || import_node_process3.default.env.VSCODE_CWD || import_node_process3.default.env.JETBRAINS_IDE || import_node_process3.default.env.VIM) && !import_node_process3.default.env.CI),

...

"unused-imports/no-unused-imports": isInEditor ? "off" : "error",

A very non-obvious behavior for a library is to disable errors in the editor. If we put both facts together, it seems that this variable does not work for WebStorm and therefore there are errors there, but not in the VSCode.

@dbaeumer
Copy link
Member

@AlexMarlow25 thanks a lot for the great investigation. Indeed very strange to disable errors in an editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants