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

Apply to JavaScript files #267

Closed
magnusriga opened this issue Jan 28, 2024 · 9 comments
Closed

Apply to JavaScript files #267

magnusriga opened this issue Jan 28, 2024 · 9 comments
Labels

Comments

@magnusriga
Copy link

The eslint-plugin-import and eslint-import-resolver-typescript docs are quite clear that the latter is needed to support tsconfig @-rules (compilerOptions.path).

I have set it up correctly, with these:

settings: {
    "import/parsers": {
       "@typescript-eslint/parser": [".ts", ".tsx"]
    },
    "import/resolver": {
       typescript: {
         project,
       },
    }
}

Where project is resolved as such:

const project = resolve(process.cwd(), "tsconfig.json");

I know that works, it comes from turborepo's examples.

The issue is when I use JavaScript files (as opposed to TypeScript). import/no-unresolved then throws an error.

Any way to fix this? Ideally, the typescript resolver should also be applied to the JavaScript files.

@JounQin
Copy link
Collaborator

JounQin commented Jan 28, 2024

You can set jsconfig.json as project. See also #161

@JounQin JounQin closed this as not planned Won't fix, can't repro, duplicate, stale Jan 28, 2024
@magnusriga
Copy link
Author

magnusriga commented Jan 28, 2024

@JounQin Thank you. But I already have a tsconfig.json, which I am using in a next.js project with JavaScript files. I would like eslint import to respect the path setting in the tsconfig.json. Is that possible? TypeScript and vscode is OK with it, as IntelliSense works fully (autocomplete, go-to-source, etc.)

@JounQin
Copy link
Collaborator

JounQin commented Jan 28, 2024

Then you should add allowJs into tsconfig.json?

Or at least you should provide a minimal reproduction.

@magnusriga
Copy link
Author

magnusriga commented Jan 28, 2024

Then you should add allowJs into tsconfig.json?

Or at least you should provide a minimal reproduction.

Hi,

I actually have allowJs, the setup all works as it should except for the fact that eslint throws a import/no-unresolved when using the aliases from tsconfig in JavaScript files.

If the tsconfig was not set up correctly, I guess IntelliSense and Go to Source would not work. But it does work.

Are you saying that this import resolver (eslint-import-resolver-typescript) should work on JS files by default, when allowJs is set?

Hmmm, let me add a minimal repo shortly.

@JounQin
Copy link
Collaborator

JounQin commented Jan 28, 2024

Are you saying that this import resolver (eslint-import-resolver-typescript) should work on JS files by default, when allowJs is set?

Yes.

@JounQin
Copy link
Collaborator

JounQin commented Jan 28, 2024

I don't understand why it's not @repo/typescript-config/base.json

https://github.com/magnusriga/turbo-tailwind/blob/c368eec5cbe6ef858b2a0b36822b5e05b6ccb832/tsconfig.json#L2

@magnusriga
Copy link
Author

@JounQin Sorry, I messed up the minimal repo. It does not show the issue. Bear with me for a few min while I recreate it.

@magnusriga
Copy link
Author

magnusriga commented Jan 28, 2024

@JounQin I was unable to recreate it. The current version of the min repo is as similar as possible to my main repo, which bizarrely started working when I restarted the devContainer. @ui/baz in foo-javascript does not show any eslint error/warning.

ESLint seems a bit slow though. Did you spot anything I did in my base eslint config that should take long?

In any case, thanks a lot for the quick response, and sorry for the lack of a good reproduction.

Any reason why it might have been necessary to restart the container? Just restarting vscode did not work.

@JounQin
Copy link
Collaborator

JounQin commented Jan 28, 2024

ESLint seems a bit slow though. Did you spot anything I did in my base eslint config that should take long?

Related #176, maybe try to use relative path for extends.

Any reason why it might have been necessary to restart the container? Just restarting vscode did not work.

Sorry, I'm lack of experience of dev container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants