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

feat: support ESLint v9 #2996

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

G-Rath
Copy link
Contributor

@G-Rath G-Rath commented Apr 7, 2024

Resolves #2948

Copy link

codecov bot commented Apr 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.37%. Comparing base (f72f207) to head (587b03e).

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2996       +/-   ##
===========================================
+ Coverage   82.18%   95.37%   +13.19%     
===========================================
  Files          93       82       -11     
  Lines        4136     3567      -569     
  Branches     1391     1257      -134     
===========================================
+ Hits         3399     3402        +3     
+ Misses        737      165      -572     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@G-Rath G-Rath force-pushed the support-eslint-v9 branch 2 times, most recently from 7c59670 to 543e378 Compare April 7, 2024 01:10
@G-Rath

This comment was marked as outdated.

@ljharb
Copy link
Member

ljharb commented Apr 8, 2024

I've just gotten back from travel, so I'll try to take a look at it in the coming days.

One likely obstacle is that all the tests assume eslintrc, but eslint 9 requires an env var to support it, otherwise it defaults to flat config. The initial support needs to test eslintrc, and it would be fine to add flat config tests in a follow-on if needed.

It's likely that the way eslint < 9's RuleTester works is subtly different than in eslint 9, so we may need an abstraction to handle that.

@G-Rath
Copy link
Contributor Author

G-Rath commented Apr 8, 2024

Yup part of this includes switching to a custom rule tester that converts the tests from eslintrc to flat config if they're running on v9, which is what we've been using in eslint-plugin-jest without issue.

@ljharb
Copy link
Member

ljharb commented Apr 8, 2024

That's great, but testing eslintrc on eslint 9 is also very important.

It'd also be great if there was a commit or two I could land separately, that worked on eslint < 9, so that only the 9-specific parts remained in this PR after that was landed and rebased :-)

@G-Rath
Copy link
Contributor Author

G-Rath commented Apr 8, 2024

If you're meaning the context helper stuff, yeah I'm happy to pull them out I just figured you'd have asked them to be tested against ESLint v9 to prove they actually worked :-)

@ljharb
Copy link
Member

ljharb commented Apr 8, 2024

You figured right :-) but i can just cherry-pick the commits out of this PR once things are working.

@G-Rath
Copy link
Contributor Author

G-Rath commented Apr 8, 2024

Right well they're already good for cherry-picking - you want to pick from e31fe5c...543e378 (sans f0853cb once #2997 is landed), and away you go.

I think you can have the eslintrc-on-v9 support by just running the whole test suite twice with the env enabled and an extra test in the custom rule tester - I'll push that up shortly

@G-Rath
Copy link
Contributor Author

G-Rath commented Apr 8, 2024

@ljharb RuleTester does not support eslintrc in v9 - the env variable is only used by the CLI

@ljharb
Copy link
Member

ljharb commented Apr 8, 2024

well that sucks, we’ll need to file an eslint issue about that gap.

@G-Rath
Copy link
Contributor Author

G-Rath commented Apr 8, 2024

I'll leave that to you as I suspect you'll have more pull :-)

@ljharb
Copy link
Member

ljharb commented Apr 8, 2024

Filed eslint/eslint#18292.

tests/src/rule-tester.js Outdated Show resolved Hide resolved
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.

Can you help me understand what withoutAutofixOutput is for?

src/rules/newline-after-import.js Outdated Show resolved Hide resolved
tests/src/rules/no-cycle.js Outdated Show resolved Hide resolved
@G-Rath

This comment was marked as outdated.

@ljharb
Copy link
Member

ljharb commented Apr 12, 2024

Totally, while it's still a draft I'm indeed just chipping away at the review :-) your effort is appreciated!

src/context.js Outdated Show resolved Hide resolved
tests/src/cli.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@G-Rath
Copy link
Contributor Author

G-Rath commented Sep 19, 2024

(codecov seems to be getting confused - sometimes its happy, sometimes its not 🤷)

@G-Rath G-Rath force-pushed the support-eslint-v9 branch 4 times, most recently from cbd057a to 6073c7f Compare September 19, 2024 02:43
@silversonicaxel
Copy link

Getting greenly exciting!

@waitingsong
Copy link

All passed!

@michaelfaith
Copy link
Contributor

A quick note to @ljharb on ordering. These two changes from the utils package will need to be released before this one:

And this PR has also absorbed this change from the core package, which hasn't merged yet: #3062

@G-Rath G-Rath marked this pull request as ready for review September 19, 2024 19:17
@G-Rath
Copy link
Contributor Author

G-Rath commented Sep 19, 2024

@ljharb in addition to the PRs mentioned by @michaelfaith, I would start with reviewing these and cherry-picking them first when you're happy:

  • 587b03e
  • 2b1dd8f
  • 5a1516a
  • 910d242 (feel free to suggest an alternative name for the function - I don't hate it but I don't love it either; ultimately I just picked something good enough to let me continue 😅 )

@michaelfaith
Copy link
Contributor

Really appreciate your commitment to this work @G-Rath. You've put some real time into this, and it'll be a big win once it lands.

@@ -116,6 +116,11 @@ exports.default = function parse(path, content, context) {
parserOptions = Object.assign({}, parserOptions);
parserOptions.ecmaFeatures = Object.assign({}, parserOptions.ecmaFeatures);

// fallback to the ecma version in languageOptions when using flat config
if (context.languageOptions) {
parserOptions.ecmaVersion = parserOptions.ecmaVersion || context.languageOptions.ecmaVersion;
Copy link
Contributor

@michaelfaith michaelfaith Sep 19, 2024

Choose a reason for hiding this comment

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

I would suggest removing this change in favor of what I added to this PR: #3061 which gets both ecmaVersion and sourceType. Also changes to utils need to be released separate. So it may make more sense to let that other PR go through and absorb that.

https://github.com/import-js/eslint-plugin-import/pull/3061/files#diff-8eaca1b6ca0fb21f508c6fde19aca39c92cabae6734eb669058ed4aadbef0c65R148-R158

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this'll go away once #3061 is landed - I'm not removing it for now because I need it for CI to be green and Jordan wants to cherry-pick stuff out anyway so there will be at least one "grand rebase" of this pull request before it gets merged 😄

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.

Support eslint v9