eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

Differences between eslint CLI and vscode linting

Open chelentos opened this issue 7 months ago • 11 comments

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:

Image

what i have in terminal:

Image

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.

chelentos avatar Apr 22 '25 10:04 chelentos

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 avatar Apr 22 '25 16:04 ljharb

@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.

chelentos avatar Apr 22 '25 20:04 chelentos

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

JounQin avatar Apr 22 '25 23:04 JounQin

@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 avatar Apr 28 '25 09:04 chelentos

@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 avatar Apr 28 '25 09:04 JounQin

@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.

chelentos avatar Apr 28 '25 10:04 chelentos

The fix is already there: #2519, no other workarounds.

JounQin avatar Apr 28 '25 10:04 JounQin

@JounQin

Hello! Any updates in X version?

chelentos avatar May 21 '25 08:05 chelentos

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.

JounQin avatar May 21 '25 08:05 JounQin

@chelentos have you solved it?

davideruby avatar Jul 08 '25 20:07 davideruby

@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

chelentos avatar Jul 09 '25 11:07 chelentos