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
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
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Oct 4, 2024
| datasource | package              | from   | to     |
| ---------- | -------------------- | ------ | ------ |
| npm        | eslint-plugin-import | 2.30.0 | 2.31.0 |


## [v2.31.0](https://github.com/import-js/eslint-plugin-import/blob/HEAD/CHANGELOG.md#2310---2024-10-03)

##### Added

-   support eslint v9 (\[[#2996](import-js/eslint-plugin-import#2996)], thanks \[[@G-Rath](https://github.com/G-Rath)] \[[@michaelfaith](https://github.com/michaelfaith)])
-   \[`order`]: allow validating named imports (\[[#3043](import-js/eslint-plugin-import#3043)], thanks \[[@manuth](https://github.com/manuth)])
-   \[`extensions`]: add the `checkTypeImports` option (\[[#2817](import-js/eslint-plugin-import#2817)], thanks \[[@phryneas](https://github.com/phryneas)])

##### Fixed

-   `ExportMap` / flat config: include `languageOptions` in context (\[[#3052](import-js/eslint-plugin-import#3052)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   \[`no-named-as-default`]: Allow using an identifier if the export is both a named and a default export (\[[#3032](import-js/eslint-plugin-import#3032)], thanks \[[@akwodkiewicz](https://github.com/akwodkiewicz)])
-   \[`export`]: False positive for exported overloaded functions in TS (\[[#3065](import-js/eslint-plugin-import#3065)], thanks \[[@liuxingbaoyu](https://github.com/liuxingbaoyu)])
-   `exportMap`: export map cache is tainted by unreliable parse results (\[[#3062](import-js/eslint-plugin-import#3062)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   `exportMap`: improve cacheKey when using flat config (\[[#3072](import-js/eslint-plugin-import#3072)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   adjust "is source type module" checks for flat config (\[[#2996](import-js/eslint-plugin-import#2996)], thanks \[[@G-Rath](https://github.com/G-Rath)])

##### Changed

-   \[Docs] \[`no-relative-packages`]: fix typo (\[[#3066](import-js/eslint-plugin-import#3066)], thanks \[[@joshuaobrien](https://github.com/joshuaobrien)])
-   \[Performance] \[`no-cycle`]: dont scc for each linted file (\[[#3068](import-js/eslint-plugin-import#3068)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Docs] \[`no-cycle`]: add `disableScc` to docs (\[[#3070](import-js/eslint-plugin-import#3070)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Tests] use re-exported `RuleTester` (\[[#3071](import-js/eslint-plugin-import#3071)], thanks \[[@G-Rath](https://github.com/G-Rath)])
-   \[Docs] \[`no-restricted-paths`]: fix grammar (\[[#3073](import-js/eslint-plugin-import#3073)], thanks \[[@unbeauvoyage](https://github.com/unbeauvoyage)])
-   \[Tests] \[`no-default-export`], \[`no-named-export`]:  add test case (thanks \[[@G-Rath](https://github.com/G-Rath)])
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Oct 4, 2024
| datasource | package              | from   | to     |
| ---------- | -------------------- | ------ | ------ |
| npm        | eslint-plugin-import | 2.30.0 | 2.31.0 |


## [v2.31.0](https://github.com/import-js/eslint-plugin-import/blob/HEAD/CHANGELOG.md#2310---2024-10-03)

##### Added

-   support eslint v9 (\[[#2996](import-js/eslint-plugin-import#2996)], thanks \[[@G-Rath](https://github.com/G-Rath)] \[[@michaelfaith](https://github.com/michaelfaith)])
-   \[`order`]: allow validating named imports (\[[#3043](import-js/eslint-plugin-import#3043)], thanks \[[@manuth](https://github.com/manuth)])
-   \[`extensions`]: add the `checkTypeImports` option (\[[#2817](import-js/eslint-plugin-import#2817)], thanks \[[@phryneas](https://github.com/phryneas)])

##### Fixed

-   `ExportMap` / flat config: include `languageOptions` in context (\[[#3052](import-js/eslint-plugin-import#3052)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   \[`no-named-as-default`]: Allow using an identifier if the export is both a named and a default export (\[[#3032](import-js/eslint-plugin-import#3032)], thanks \[[@akwodkiewicz](https://github.com/akwodkiewicz)])
-   \[`export`]: False positive for exported overloaded functions in TS (\[[#3065](import-js/eslint-plugin-import#3065)], thanks \[[@liuxingbaoyu](https://github.com/liuxingbaoyu)])
-   `exportMap`: export map cache is tainted by unreliable parse results (\[[#3062](import-js/eslint-plugin-import#3062)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   `exportMap`: improve cacheKey when using flat config (\[[#3072](import-js/eslint-plugin-import#3072)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   adjust "is source type module" checks for flat config (\[[#2996](import-js/eslint-plugin-import#2996)], thanks \[[@G-Rath](https://github.com/G-Rath)])

##### Changed

-   \[Docs] \[`no-relative-packages`]: fix typo (\[[#3066](import-js/eslint-plugin-import#3066)], thanks \[[@joshuaobrien](https://github.com/joshuaobrien)])
-   \[Performance] \[`no-cycle`]: dont scc for each linted file (\[[#3068](import-js/eslint-plugin-import#3068)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Docs] \[`no-cycle`]: add `disableScc` to docs (\[[#3070](import-js/eslint-plugin-import#3070)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Tests] use re-exported `RuleTester` (\[[#3071](import-js/eslint-plugin-import#3071)], thanks \[[@G-Rath](https://github.com/G-Rath)])
-   \[Docs] \[`no-restricted-paths`]: fix grammar (\[[#3073](import-js/eslint-plugin-import#3073)], thanks \[[@unbeauvoyage](https://github.com/unbeauvoyage)])
-   \[Tests] \[`no-default-export`], \[`no-named-export`]:  add test case (thanks \[[@G-Rath](https://github.com/G-Rath)])
@Yegorich555
Copy link

Yegorich555 commented Oct 8, 2024

I'm getting error:

Config "import/recommended": Key "plugins": Cannot redefine plugin "import" with new flat config. Am I missing something ?

Update: nevermind. Looks like in my case some another plugin re-use same plugin

@Arkellys
Copy link

Arkellys commented Oct 9, 2024

I'm getting error:

Config "import/recommended": Key "plugins": Cannot redefine plugin "import" with new flat config. Am I missing something ?

Update: nevermind. Looks like in my case some another plugin re-use same plugin

Do not define the plugin import if you use the recommended configuration, it's already defined.

khassel pushed a commit to MagicMirrorOrg/MagicMirror that referenced this pull request Oct 13, 2024
eslint-plugin-import was missing since the switch to
[v9](#3558). They
finally
[support](import-js/eslint-plugin-import#2996)
it so we can re-add it.
devjiwonchoi added a commit to vercel/next.js that referenced this pull request Oct 14, 2024
> [!WARNING]
> **Breaking Change:** Now uses `[email protected]` which
has a new violation disallowing Component names starting with anything
but an uppercase letter. See
https://github.com/facebook/react/releases/tag/eslint-plugin-react-hooks%405.0.0
for more details.

Adds support of ESLint v9 to `eslint-plugin-next`, `eslint-config-next`
and `next lint`.

Does not require using the new flat config format. `next lint` will
automatically ensure the old config format can be used.

### Why?

As `eslint-plugin-react-hooks` has been updated for ESLint v9 support
and is a helpful package for Next v15 upgrade, unblock the restrictions
to upgrade to ESLint v9.

Also, ESLint v8 is [End of
Life](https://eslint.org/blog/2024/09/eslint-v8-eol-version-support/#:~:text=ESLint%20v8.-,x%20end%20of%20life%20is%20October%205%2C%202024,x%20on%20October%205%2C%202024.)
support since Oct 5th, so is good to unblock v9 now.

Plugins bumped:
- [x]
[@rushstack/eslint-patch](microsoft/rushstack#4719)
([v1.10.3](https://www.npmjs.com/package/@rushstack/eslint-patch/v/1.10.3?activeTab=versions)
no release post, confirmed on NPM)
- [x]
[@typescript-eslint/eslint-plugin](typescript-eslint/typescript-eslint#9002)
([v8.0.0](typescript-eslint/typescript-eslint#9002 (comment)))
- [x]
[eslint-plugin-import](import-js/eslint-plugin-import#2996)
([v2.31.0](https://github.com/import-js/eslint-plugin-import/releases/tag/v2.31.0))
- [x]
[eslint-plugin-jsx-a11y](jsx-eslint/eslint-plugin-jsx-a11y#1009)
([v6.10.0](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/releases/tag/v6.10.0))
- [x]
[eslint-plugin-react](jsx-eslint/eslint-plugin-react#3759)
([v7.35.0](https://github.com/jsx-eslint/eslint-plugin-react/releases/tag/v7.35.0))
- [x]
[eslint-plugin-react-hooks](facebook/react#28773)
([v5.0.0](https://github.com/facebook/react/releases/tag/eslint-plugin-react-hooks%405.0.0))

We have to switch to ESLint v9 in our repo due to a pnpm bug where it
automatically uses ESLint v9 even though we only installed it via
`eslint-v9: npm:[email protected]`. This is a pnpm bug that wouldn't happen
with Yarn v1, v4 nor NPM.

Closes #64409
Closes #64114
Closes #64453

Closes NEXT-3293

---------

Co-authored-by: Sebastian "Sebbie" Silbermann <[email protected]>
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