-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Upgrade ESLint to v9 #65648
base: trunk
Are you sure you want to change the base?
Upgrade ESLint to v9 #65648
Conversation
Awesome work @shvlv starting this PR. Thank you so much. The number of breaking changes is overwhelming. It won't be an easy upgrade for the folks using |
Are there automated migration tools that can help with migration? Were they used in this PR? It would be helpful for folks dealing with this breaking change to document how they can migrate and what tooling is available. |
Yes, tools exist. @eslint/migrate-configTo migrate config, https://eslint.org/docs/latest/use/configure/migration-guide#migrate-your-config-file could be used. However, as the documentation says, it's appropriate chiefly for static configuration files ( In projects I participated in, we often used the following approach: const defaultConfig = require( '@wordpress/scripts/config/.eslintrc.js' );
module.exports = {
...defaultConfig,
settings: {
'import/resolver': {
typescript: {},
},
},
}; But yes, it will not work now for several reasons, and I'm not sure the migration tool could help either. In general, migration to v9 is pretty complicated for several reasons:
But it's complex for the Gutenberg giant monorepo and should be easier for consuming projects. eslint-transformsIt can be used to migrate custom rules to the new API (https://www.npmjs.com/package/eslint-transforms and https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/). I tried it for @eslint/config-inspectorIt's the new tool to make debugging easier (https://eslint.org/docs/latest/use/configure/debug#use-the-config-inspector and https://github.com/eslint/config-inspector). It doesn't work if you have config errors. But now it works like the following: We can consider adding the
Yes, we should mention these tools in the documentation (or a blog post). However, I think documentation with examples of how-to is even more important. |
Last update:
Regarding the last one, ESLint v9 doesn't support multiple configurations as it used to. I.e., it stops after finding the parent configuration. I see the pros and cons of this decision. Pros: we have everything in a single place; it's transparent; we can merge duplicated rules. Cons: we already have 700+ lines in the config file. We can keep it as is and consider refactoring in the future. Refactoring can be done in the two directions:
Current status:
|
Hi, maybe I understand things incorrectly, but it seems to me that it's still possible to have multiple config files, you just have a different mechanism for using them - importing. So each package can have its own config, which imports some shared general config much like you import and use configs from third-party plugins. |
This is gonna be a very painful change for the ecosystem. Is there any way we could reduce the burden for users of these packages? For example by simultaneously supporting v8 and v9 or so? |
@marekdedic, I think we are talking about different things. We have the following structure:
When we run ESLint V8 from the root directory, and ESLint starts to lint files inside
But it does not work in this way now - https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file-resolution:
That means if you run |
@swissspidy, the problem is Other issues are resolvable:
|
@shvlv You are right, we are misunderstanding each other. :) |
Last updates:
|
Hi @shvlv - check out eslint 9.12, I think they may have added exactly what we were talking about last week - see eslint/eslint#18742 |
Last updates:
We are almost there:
@marekdedic I didn't test the last ESLint release, but from the description, I see it's exactly what we talked about. But when I'm thinking about root |
Hi @gziolo, technically, we are close to finishing. We have to additionally test the The main question is whether we are going to introduce this breaking change. You can check my consideration here: #65648 (comment). I think the |
Any progress on this? |
We are trying different options to make the upgrade smoother for end users. But there is no clear and robust solution. Maybe we can make |
I've checked the compatibility issue once more. The important notes:
This means we can support the same range as
Sure, the text should be updated to refer to the updated documentation with a migration guide. Additionally ESLint v9 emits
I've tested the following combinations (linting works as expected, both configurations are supported):
Also, I've rebased onto trunk. The new version of |
…ugin-testing-library
@shvlv, excellent progress on backward compatibility support for ESLint 8 in existing projects. Overall, it's a lot of changes so it might require a larger group of folks from @WordPress/gutenberg-core to chime in to get it to the finish line.
@Mamaduka and @tyxla, can you check these changes based on your experience on the work with React compiler? |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @ghostintranslation. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There's no way around it, unfortunately. React Compiler needs the rules of hooks to be followed in order to work for the files in question. Prefixing a hook with an underscore, passing a hook around as a prop, or conditionally executing a hook are all violations that are not allowed. As a temporary fix, disabling the rules of hooks for those files (which was done here) is one way to go - although we should make sure that it's only temporary. Alternatively, we've used the |
What?
Upgrade ESLint to v9.
Why?
Fixes #64782
Fixes #62496.
ESLint was moving to the new flat config and new API — https://eslint.org/docs/latest/use/migrate-to-9.0.0. The community made great progress supporting v9 — eslint/eslint#18391.
How?
The following parts were updated:
eslint-plugin
to support the flat formatlint-js
command to support the v9 CLIpackage.json
to upgrade ESLint pluginsSeveral plugins are incompatible with ESLint v9 and were fixed with
eslint/compat
helper:Was released with v2.31.0eslint-plugin-import
. The issue and PR exist. We expect it to be released soon. Note that the forked plugin https://github.com/un-ts/eslint-plugin-import-x supports v9.eslint-plugin-react-hooks
supports v9 only in [RC version ] (eslint-plugin-react-hooks & "Flat Config" (ESLint 9) facebook/react#28313). We hope it will be released soon.. Released with v7.0.0.eslint-plugin-testing-library
supports flat config but not support updated API. Released with 0.10.0.eslint-plugin-storybook
supports v9 in canary version. But it might be problems with a glob expression. The overall issue - Suport ESLint v9 storybookjs/eslint-plugin-storybook#157eslint-plugin-ssr-friendly
doesn't support flat config and new API. The plugin looks unmaintained; we can consider moving these rules to@wordpress/eslint-plugin.
The issue - [Breaking Changes] Support ESLint 9 kopiro/eslint-plugin-ssr-friendly#30.eslint-plugin-eslint-comments
was replaced by@eslint-community/eslint-plugin-eslint-comments
- https://github.com/eslint-community/eslint-plugin-eslint-comments (see mysticatea/eslint-plugin-eslint-comments#79 (comment)).Testing Instructions
Run
npm run lint:js
.Current status
With upgrading plugins, new rules were introduced that have to be handled on the root config. Also, maybe the new configuration still does not completely reflect the previous one (while I strived for that goal). Some issues are repeated many times, so they can be easily addressed (like
@typescript-eslint/no-explicit-any
orno-undef
inreact-navite-editor
).Also, documentation for
eslint-plugin,
script
, and inside/docs
should be double-checked.