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

[New] support eslint 9 #2996

Merged
merged 4 commits into from
Sep 30, 2024
Merged

[New] support eslint 9 #2996

merged 4 commits into from
Sep 30, 2024

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

Attention: Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Project coverage is 95.07%. Comparing base (55fa203) to head (a5020a6).

Files with missing lines Patch % Lines
src/rules/no-default-export.js 66.66% 1 Missing ⚠️
src/rules/no-named-export.js 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2996      +/-   ##
==========================================
- Coverage   95.20%   95.07%   -0.14%     
==========================================
  Files          82       82              
  Lines        3565     3571       +6     
  Branches     1245     1251       +6     
==========================================
+ Hits         3394     3395       +1     
- Misses        171      176       +5     
Flag Coverage Δ
95.07% <77.77%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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
@G-Rath

This comment was marked as resolved.

@ljharb

This comment was marked as resolved.

@michaelfaith
Copy link
Contributor

michaelfaith commented Sep 26, 2024

I'll volunteer to put that change in.

Here's that update for the cache key we talked about: #3072 if you want to review.
I tested it against this branch but also don't think this pr should have to wait on that one.

ljharb pushed a commit to G-Rath/eslint-plugin-import that referenced this pull request Sep 26, 2024
ljharb pushed a commit to michaelfaith/eslint-plugin-import that referenced this pull request Sep 26, 2024
Discovered this issue in import-js#2996 (comment)

This change improves the logic for generating the cache key used for both the exportMap cache and resolver cache when using flat config. Prior to this change, the cache key was a combination of the `parserPath`, a hash of the `parserOptions`, a hash of the plugin settings, and the path of the file. When using flat config, `parserPath` isn't provided. So, there's the possibility of incorrect cache objects being used if someone ran with this plugin using different parsers within the same lint execution, if parserOptions and settings are the same. The equivalent cacheKey construction when using flat config is to use `languageOptions` as a component of the key, rather than `parserPath` and `parserOptions`. One caveat is that the `parser` property of `languageOptions` is an object that oftentimes has the same two functions (`parse` and `parseForESLint`). This won't be reliably distinct when using the base JSON.stringify function to detect changes. So, this implementation uses a replace function along with `JSON.stringify` to stringify function properties along with other property types.

To ensure that this will work properly with v9, I also tested this against import-js#2996 with v9 installed. Not only does it pass all tests in that branch, but it also removes the need to add this exception: import-js#2996 (comment)
@G-Rath G-Rath requested a review from ljharb September 27, 2024 03:17
@G-Rath
Copy link
Contributor Author

G-Rath commented Sep 27, 2024

@ljharb the codecov check seems to have wandered off entirely now, but I can promise you those lines are now covered so this should be all set

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.

After addressing my comments (ie, rebase), if tests pass, and especially if it's been tested locally by you folks in situ, this seems ready to go!

tests/src/rules/no-default-export.js Outdated Show resolved Hide resolved
tests/src/rules/no-named-export.js Outdated Show resolved Hide resolved
@ljharb ljharb changed the title feat: support ESLint v9 [New] support eslint 9 Sep 27, 2024
@G-Rath G-Rath force-pushed the support-eslint-v9 branch 2 times, most recently from 925a6a8 to a5020a6 Compare September 27, 2024 17:52
@michaelfaith
Copy link
Contributor

It looks like removing those two tests caused the coverage on those two lines to fall off again.

@michaelfaith
Copy link
Contributor

michaelfaith commented Sep 27, 2024

It looks like that condition was never covered, so expanding it without adding a new test, is flagging the lack of coverage. If you add a valid test to each rule that passes in parserOptions: {sourceType: 'commonjs'}, that should cover those lines.

@G-Rath
Copy link
Contributor Author

G-Rath commented Sep 27, 2024

Yeah @ljharb landed my tests using the test helper which sets the source type as module, which makes them moot and I'd forgotten that was why I'd not used that helper when I rebased this morning 😅

@ljharb should I push the tests back up here or do you want to fix them on main?

@ljharb
Copy link
Member

ljharb commented Sep 28, 2024

ahh, gotcha. i'll fix them on main and rebase this afterwards.

@ljharb ljharb merged commit 5a51b9a into import-js:main Sep 30, 2024
319 checks passed
@ljharb
Copy link
Member

ljharb commented Sep 30, 2024

@michaelfaith and @G-Rath (and @soryy708), please do file an expense against https://opencollective.com/eslint-plugin-import for what you think is reasonable for all of your contributions in the last year.

@G-Rath G-Rath deleted the support-eslint-v9 branch September 30, 2024 20:18
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