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

Support eslint flat config

Open OlivierZal opened this issue 1 year ago • 8 comments

OlivierZal avatar Sep 03 '23 22:09 OlivierZal

@OlivierZal any progress on this? you are a dependency to the airbnb styleguide which can't support eslint 9 & flat config yet

aaarichter avatar May 14 '24 13:05 aaarichter

Hi, I confess I gave up (too many dependencies) and don't use the airbnb config anymore...

OlivierZal avatar May 14 '24 14:05 OlivierZal

In that case, anyone who wants to continue this PR, please don't open a new PR - instead, comment here with a link to a branch or commit, and I can pull in your changes.

ljharb avatar May 14 '24 18:05 ljharb

hey @ljharb , I added flat config support in my fork: https://github.com/vonBrax/eslint-plugin-import/tree/feat/flat-config.

There are however a few points to discuss.

I based my solution similar to https://github.com/ember-cli/eslint-plugin-ember, which I found when reading https://github.com/eslint/eslint/issues/18095.

The advantage is that it is backwards compatible, but not so ergonomic since one does need to individually import the necessary configs instead of just one default import, like here for example: https://github.com/vonBrax/eslint-plugin-import/blob/fbb21b08c344c1306f92d0b466b5c0b647bbbcca/tests/files/flat-config-typescript/eslint.config.js#L1-L2

The eslint recommendation is to rename the old configs by appending "-legacy" to their names. We then would need only a single import, but that would also probably be a breaking change and it would also require fixing all the failing tests.

Because this plugin apparently also parse files "manually", I had to include estree as a dependency since I eslint doesn't seem to externalize it, otherwise we would ran into the parserPath or languageOptions.parser is required is required. Wouldn't it be possible to somehow use eslint to do the parsing here and thus leave the parsing configuration up to the user (estree, babel, typescript, etc)?

I've included a few test cases alongside my changes, but since I'm not familiar with this project nor with writing eslint plugins, I'm not sure if I'm missing something here.

Let me know what you think. I'm also happy to open a PR since I took a very different path than what was initially proposed by this PR.

vonBrax avatar May 22 '24 06:05 vonBrax

Existing entrypoints must continue to work in places they work now. I'd rather force flat config users to use a new entrypoint than force eslintrc users to use a "legacy" one.

It would of course be ideal if we could delegate as much parsing as possible to eslint.

If your fork's added tests can be made to pass, that seems great! The important part is that every existing test must continue to pass, in order to not have a breaking change.

ljharb avatar May 22 '24 06:05 ljharb

Hey there,

I was wondering if you could explain why you're trying to avoid breaking changes or point us to a reference or explanation? @ljharb

At the moment the whole eslint ecosystem has to resolve breaking changes due to v9. I'd argue that it's a good opportunity to stop supporting everything before v8. There will be no such opportunity in the near future again. (let it gooo 🎶)

thanks in advance

error-four-o-four avatar Jun 04 '24 15:06 error-four-o-four

@error-four-o-four That's been the case with every eslint major, and I haven't had to drop compat yet, I'm not sure why I should start now. Breakage is COSTLY - as you can see with eslint's own breakage. I refuse to inflict unnecessary cost on millions of users solely for expediency - that would be sociopathic.

ljharb avatar Jun 04 '24 23:06 ljharb

https://github.com/un-ts/eslint-plugin-import-x/issues/24#issuecomment-1902271741

I apologize.

I haven't caught up with all the discussions yet and there's quite a lot to read.

error-four-o-four avatar Jun 05 '24 05:06 error-four-o-four