antfu / eslint-config

Anthony's ESLint config preset

Home Page:https://eslint-config.antfu.me/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make configurable behaviour to show errors in editor or not

AlexMarlow25 opened this issue · comments

Clear and concise description of the problem

In our project we encountered non-obvious behavior of eslint work across developers. Because we use both editors in our work, WebStorm and VSCode, we get different ESLint behaviours. I described this more detailed in the microsoft/vscode-eslint issue. In short - we get some errors in the WebStorm, but don't in the VSCode. And my first thought was - it is a problem on VSCode's side. But I was a little upset, when I saw isInEditor logic. Do we really need this inside this library if we can turn off these errors in the editor by ourselves, for example?
Anyway, if it works as intended and we don't want to change anything in the config logic, I think there is a bug with defining the JETBRAINS_IDE variable. But we need to test it to be sure.

Suggested solution

Make it configurable by some property in the config options.

Alternative

Remove this behavior and leave it to the user's choice.

Additional context

No response

Validations

The condition is provided as the default value, which means you can disable it by providing isInEditor: false in the factory

commented

Why would you want the editor and the command line to behave differently by default? And I think almost nobody known the side effects controled by isInEditor 😂

It makes me spend a lot of time to explore the root reason, fortunately @AlexMarlow25 encounter the same problem, and the truth become more and more clear.

Why would you want the editor and the command line to behave differently by default?

It won't make sense until you use a pre-commit hook, as described here. Then it makes a lot of sense.

Some rules you want to enforce in a codebase, but do not want to run on-save. A prime example is no-unused-imports. You don't want it running on-save because that can get noisy/tiresome when your imports keep getting removed while you're actively writing code. Instead, you disable it in your editor and let your pre-commit hook handle it automatically.

commented

I see, it seems that isInEditor: true must work with pre-commit hook eslint --fix. But I am still using eslint only in pre-commit hook.

Because in editor you don't always want unused variables/imports to be removed as you are probably on the process of refactoring that you are going to use it soon. It's my workflow and I found it better that way - and you can disable that anyway.

commented

Because in editor you don't always want unused variables/imports to be removed

I've got used to it 😂

After understand the purpose, I think this feature is pretty useful, and I have fixed the git pre-commit usage for my latest project, use eslint --fix to replace just run eslint directly. Maybe such details should be indicated in the documentation?

Maybe such details should be indicated in the documentation?

You mean the editor's conditional behavior? Yeah totally, and PR welcome :)

commented

Furthermore, isInEditor should alse support WebStorm. But I didn't use it 😂