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-relative-import-paths plugin not reported as error by the extension in some cases #1594

Closed
jgoux opened this issue Jan 31, 2023 · 8 comments
Labels
bug Issue identified by VS Code Team member as probable bug
Milestone

Comments

@jgoux
Copy link

jgoux commented Jan 31, 2023

Hello,

I'm using https://github.com/MelvinVermeer/eslint-plugin-no-relative-import-paths and I'm having trouble having vscode-eslint reporting errors in my import statements.

Running eslint CLI against my file works as expected, the error is seen and fixable, but somehow vscode-eslint is missing it.

What's even more strange is that if I change the plugin's options, vscode-eslint is able to pick up the rule. But the combination that I want to use isn't detected.

With the CLI:
image

You can see that vscode-eslint isn't seeing the issue (line 3 should be in error).

If I change the options of the plugin from:

{
"no-relative-import-paths/no-relative-import-paths": [
      "error",
      { "allowSameFolder": true, "rootDir": "src", "prefix": "~" },
    ]
}

to:

{
"no-relative-import-paths/no-relative-import-paths": [
      "error",
      { "allowSameFolder": true, "rootDir": "", "prefix": "~" },
    ]
}

The vscode extension is now able to see the error:

image

It seems that no matter what I put in rootDir, if it's not an empty string, vscode-eslint won't report the error (but the CLI works as expected, and there is no open issue about the plugin not working as I intend to use it in their repository).

It's the only rule acting this way among my numerous other rules. 😅

The extension is using my local eslint library installed in my monorepo:
[Info - 11:28:27] ESLint library loaded from: /Users/jgoux/Documents/code/snaplet-labs/node_modules/eslint/lib/api.js

@dbaeumer
Copy link
Member

@jgoux this is very likely a problem of a correct working directory setup. Looks like validation happens correctly in the terminal when in the api directory. Such a working directory must be know to the extension as well. See the setting eslint.workingDirectories

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Jan 31, 2023
@jgoux
Copy link
Author

jgoux commented Jan 31, 2023

See the setting eslint.workingDirectories

This is my workingDirectories setting:

{
"eslint.workingDirectories": [
    {
      "pattern": "./apps/*/"
    },
    {
      "pattern": "./packages/*/"
    }
  ],
}

It reflects all my apps/packages roots in my monorepo.

@dbaeumer
Copy link
Member

dbaeumer commented Feb 1, 2023

Looks ok. Can you please provide me with a Github repository I can clone that demos what you are seeing. This ensures that we both look at the same setup.

@jgoux
Copy link
Author

jgoux commented Feb 13, 2023

@dbaeumer Sorry for the delay! Here is a reproduction: https://github.com/jgoux/vscode-eslint-imports

I tested in a non-monorepo setup and VSCode ESLint was able to report the error correctly. So there is definitely something related to the monorepo structure here.

@dbaeumer
Copy link
Member

The underlying problem is that the plugin does path math without using the path npm module which results in a path with // which then doesn't correctly match. See MelvinVermeer/eslint-plugin-no-relative-import-paths#23

@dbaeumer
Copy link
Member

See also #1605 to avoid these situations as well.

@dbaeumer dbaeumer added this to the 2.4.2 milestone Feb 13, 2023
@dbaeumer dbaeumer added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Feb 13, 2023
@jgoux
Copy link
Author

jgoux commented Feb 14, 2023

Thanks for tracking it down!

Is your PR fixing the issue or do we have to fix the issue in MelvinVermeer/eslint-plugin-no-relative-import-paths#23 ?

@dbaeumer
Copy link
Member

Mine works around it but MelvinVermeer/eslint-plugin-no-relative-import-paths#23 should be addressed as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants