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

feature request: FlatConfig support #318

Closed
Leonardo-Vieira-Andela opened this issue Oct 30, 2024 · 13 comments · Fixed by #326
Closed

feature request: FlatConfig support #318

Leonardo-Vieira-Andela opened this issue Oct 30, 2024 · 13 comments · Fixed by #326

Comments

@Leonardo-Vieira-Andela
Copy link

What

We want to start using eslint-import + eslint-import-resolver-typescript but there is no flatConfig support. It would be very beneficial for said support to be added.

Kind regards!

@JounQin JounQin closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2024
@SukkaW
Copy link
Collaborator

SukkaW commented Oct 30, 2024

If you want to import eslint-import-resolver-typescript directly in your eslint.config.js without using a path or string, plz check this proposal out: un-ts/eslint-plugin-import-x#40 (comment)

I am going to implement that this weekend.

@dbudwin
Copy link

dbudwin commented Nov 22, 2024

This would be super helpful to have an example of how to use this package with the newer ESLint flat config (i.e. how do I use this package in an eslint.config.js file)

@JounQin The links you have reference the sister package of this one eslint-plugin-import. I've been able to use their flat config example. But I would like to see a flat config example for eslint-import-resolver-typescript too.

@SukkaW
Copy link
Collaborator

SukkaW commented Nov 22, 2024

This would be super helpful to have an example of how to use this package with the newer ESLint flat config (i.e. how do I use this package in an eslint.config.js file)

For eslint-plugin-import-x, the proposed usage would be:

// eslint.config.js
import { createImportXTypeScriptResolver } from 'eslint-import-typescript-resolver';

// ...
settings: {
  'import-x/resolvers-next': [
     createImportXTypeScriptResolver(options)
  ]
}
/// ...

Note that this is still the proposal but we will be implementing this soon.

@melroy89
Copy link

https://github.com/import-js/eslint-plugin-import#config---flat-eslintconfigjs

Yes I want something like import importPlugin from 'eslint-import-resolver-typescript'; .. and then use it: importPlugin.flatConfigs.recommended or something within my eslint.config.mjs file.

@ljharb
Copy link
Member

ljharb commented Nov 23, 2024

@melroy89 if you want the import plugin you'd need to import eslint-plugin-import; the resolver isn't same as the plugin.

@melroy89
Copy link

melroy89 commented Nov 23, 2024

@melroy89 if you want the import plugin you'd need to import eslint-plugin-import; the resolver isn't same as the plugin.

Thanks for you response! I see, I'm using my typescript project with moduleResolution set to nodenext: "moduleResolution": "NodeNext", and I use ES6 modules "module": "NodeNext". Which works all great. But using eslint-plugin-import will result in that it can't find the imports.

Meaning the plugin has difficulties finding the ./somemodule.js file (since well in TypeScript that JS file is indeed not there yet). eslint-plugin-import will fail to find it and unable to deal with this module resolution, hence I was thinking I needed this resolver-typescript plugin would help me out, I believe you mentioned that somewhere in an issue ticket at the eslint-plugin-import repository.

ps. I'm also using SWC during fast development (and tsc for production builds).

@SukkaW
Copy link
Collaborator

SukkaW commented Nov 24, 2024

@melroy89 You can vote up my proposal at un-ts/eslint-plugin-import-x#40 (comment) which will resolve your issue. You will be able to use eslint-import-resolver-typescript w/ eslint-plugin-import-x like this: #318 (comment)

@mcshaman
Copy link

mcshaman commented Nov 28, 2024

The problem I have found ,as somebody who is not familiar with ESLint configs, is trying to wrap my head around two types of config at the same time because various plugins support, promote and document in different ways.

I am setting up an ESLint config from scratch using the init tool, so I presented with the new flat file format (which took a tone of reading to work out what the difference is). I need it to support my TS aliases so thats why I'm looking at slint-import-resolver-typescript.

I too, like the OP, thought it needed an exported flat config module because that how all the other plugins I have implemented so far work. Digging deeper and based on @ljharb comment I assume it needs to be added to a config object though I'm not sure how. It would be helpful, at the very least, if there was an example in the readme of implementing this plugin for flat config.

This is what I have so far but it doesn't seem to be working:

import pluginImportX from "eslint-plugin-import-x";

export default [
	{
		...pluginImportX.flatConfigs.recommended,
		settings: {
			"import-x/parsers": {
				"@typescript-eslint/parser": [".ts", ".tsx"],
			},
			"import-x/resolver": {
				typescript: {
					alwaysTryTypes: true,
				},
			},
		},
	},
]

So I am trying to extend the import-x flat config and add the eslint-import-resolver-typescript config from the readme. But yeah... Doesn't work and I don't know why or if I'm doing it right/wrong. Do I need to import eslint-import-resolver-typescript?

@SukkaW
Copy link
Collaborator

SukkaW commented Dec 2, 2024

The flat config support for custom resolvers is implemented here at eslint-plugin-import-x: un-ts/eslint-plugin-import-x#192

This allows you to use require/import or any js objects as the import resolver. The new resolver design of eslint-plugin-import-x will also allow the creation of a reusable resolver instance across many resolve function invocations to improve performance.

The eslint-import-resolver-typescript will also adopt the new resolver design ASAP!

@SukkaW SukkaW reopened this Dec 2, 2024
@devuxer
Copy link

devuxer commented Dec 2, 2024

https://github.com/un-ts/eslint-plugin-import-x#configuration-new-eslintconfigjs

https://github.com/import-js/eslint-plugin-import#config---flat-eslintconfigjs

Not sure what's your meaning.

@JounQin,

The documentation for this project (eslint-import-resolver-typescript) says:

Configuration: Add the following to your .eslintrc config:

The problem is that .eslintrc is deprecated. The new way is to use eslint.config.mjs. How do we configure eslint-plugin-import with the typescript resolver to work with the new flat eslint.config files?

Most people using TypeScript and ESLint will want to use the new typescript-eslint config, so examples for all of this together would be especially helpful.

@mcshaman
Copy link

mcshaman commented Dec 3, 2024

I finally got eslint-import-resolver-typescript working with my flat file. Posted about it in this related issue.

@devuxer

This comment has been minimized.

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

Successfully merging a pull request may close this issue.

8 participants