eslint-import-resolver-typescript icon indicating copy to clipboard operation
eslint-import-resolver-typescript copied to clipboard

Inherit `project` configuration from `@typescript-eslint/parser`'s `parserOptions`

Open carlocorradini opened this issue 2 years ago • 8 comments

Using @typescript-eslint/parser is recommended to set project in parserOptions.

We also need to add the project in import/resolver-> typescript when using eslint-import-resolver-typescript.

Can we omit the first project or do we need both even though they are almost the same?

Thanks!

carlocorradini avatar Apr 05 '22 08:04 carlocorradini

PR welcome if you have the idea about how to implement it.

JounQin avatar Apr 05 '22 09:04 JounQin

Instead of reading project from import/resolver -> typescript can we read it from parserOptions?

As far as I know, to add Typescript support to eslint, @typescript-eslint/parser is a must. Therefore, I think project option should be read from the latter and not from a custom one that can create confusion and duplication.

Please, add your thoughts on this. Maybe I am wrong or this has been done for a known issue/purpose.

carlocorradini avatar Apr 05 '22 09:04 carlocorradini

eslint-import-resolver-typescript is used by eslint-plugin-import, not any parser, so it can only use things passed by eslint-plugin-import, it has no idea about the parserOptions.

JounQin avatar Apr 05 '22 09:04 JounQin

Ok, there is a purpose. So, there are no workarounds (as far as I understood)?

carlocorradini avatar Apr 05 '22 09:04 carlocorradini

Right

JounQin avatar Apr 05 '22 10:04 JounQin

One of the problems I am running in to is that eslint-import-resolver-typescript does not allow me to add (or doesn't care about adding) tsconfigRootDir: __dirname, into the settings like the below:

//...
parserOptions: {
	tsconfigRootDir: __dirname,
	project: './tsconfig.json',
},
settings: {
	'import/resolver': {
		typescript: {
			alwaysTryTypes: true,
			tsconfigRootDir: __dirname,
			project: './tsconfig.json',
		},
	},
},

Adding the tsconfigRoorDir is required in a monorepo to make @typescript-eslint work with each individual package, otherwise eslint keeps only looking for configs in the monorepo root, rather than linting rules set by each package.

If the import/resolver were able to use the same values as passed by parserOptions, that would help to solve this issue.

MWhite-22 avatar Jun 14 '22 18:06 MWhite-22

I still don't get it why not just project: __dirname

JounQin avatar Jun 14 '22 23:06 JounQin

This issue would be resolved after https://github.com/import-js/eslint-plugin-import/pull/2519 been merged.

JounQin avatar Aug 17 '22 23:08 JounQin