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

Support eslint flat config #2873

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

OlivierZal
Copy link

No description provided.

@OlivierZal OlivierZal force-pushed the olivierzal/imports_rules/eslint_flat_config_support branch 2 times, most recently from d20d08a to b0da628 Compare September 4, 2023 11:18
@OlivierZal OlivierZal force-pushed the olivierzal/imports_rules/eslint_flat_config_support branch from b0da628 to 0102dc8 Compare September 4, 2023 11:41
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be great to have some kind of test that this actually works, perhaps with a test fixture project that uses the flat config, and we run eslint on it and assert on the output?

@aaarichter
Copy link

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

@OlivierZal
Copy link
Author

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

@ljharb
Copy link
Member

ljharb commented May 14, 2024

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 ljharb mentioned this pull request May 16, 2024
@vonBrax
Copy link

vonBrax commented May 22, 2024

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 eslint/eslint#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.

@ljharb
Copy link
Member

ljharb commented May 22, 2024

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.

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

Successfully merging this pull request may close these issues.

None yet

4 participants