eslint-plugin-import
eslint-plugin-import copied to clipboard
Differences between eslint CLI and vscode linting
Hello!
I've upgraded to eslint@9 in my project and have some issues with linting.
Linting of import/order errors is different in CLI/vscode.
What i'm getting in vscode:
what i have in terminal:
Maybe it's caused by several eslint configs or aliases, but i think i'm using all needed settings for this.
I've made repo with reproduction of this problem: https://github.com/chelentos/vscode-eslint-repr
There are vscode settings in README.
Configs for eslint you can find here: https://github.com/gravity-ui/eslint-config Import/order config: https://github.com/gravity-ui/eslint-config/blob/main/import-order.js
I've already created issue in vscode plugin repo, but maybe you can help me too.
The CLI is the source of truth, so if vscode is different, it's the one that's broken. I will definitely try to take a look when I can, thanks for the repro repo!
@ljharb
The CLI is the source of truth, so if vscode is different, it's the one that's broken
I think yes, but...
It seems to me that vscode linting is more accurate. It's trying to divide external lib and internal alias that looks like external lib.
I didn't read the repro actually, but there could be a chance that resolver doesn't know about correct ESLint cwd from VSCode because there in no such info passed into resolver.
See also #2108
@ljharb @JounQin
FYI
The problem might be in resolving ts aliases not as internal.
I've tried to add this code in config in repro repo:
settings: {
'import/internal-regex': '^@my-test-package/'
}
and the difference in linting has gone.
Where should I look to make possible fix?
@chelentos You're just by passing the resolving step and mark those packages as internal directly, it's not a fix, just a workaround.
https://github.com/import-js/eslint-plugin-import/blob/da5f6ec13160cb288338db0c2a00c34b2d932f0d/src/core/importType.js#L21-L24
The root cause is already described at #2108, and the fix #2519 is alreay there for a long time. @ljharb
@JounQin
Could you help me one more time please.
Is there any 100% workaround of this problem now? To not specifying every ts alias as internal regex.
The fix is already there: #2519, no other workarounds.
@JounQin
Hello! Any updates in X version?
Hello! Any updates in X version?
Not yet, I was focusing on https://github.com/es-tooling/eslint-plugin-jsx-a11y-x recently.
@chelentos Here we go: https://github.com/un-ts/eslint-plugin-import-x/pull/335, please try eslint-plugin-import-x v4.13.0 and eslint-import-resolver-typescript v4.4.0.
@chelentos have you solved it?
@chelentos have you solved it?
Haven't tried eslint-plugin-import-x yet, but solved like this https://github.com/microsoft/vscode-eslint/issues/2006#issuecomment-2858366329