-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Add ESLint flat config example, fix ESLint name #7246
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size changes📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
| 'react-compiler/react-compiler': "error", | ||
| 'react-compiler/react-compiler': 'error', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the quote style here consistent with the other quotes
| 'eslint-plugin-react-compiler': reactCompiler, | ||
| }, | ||
| rules: { | ||
| 'react-compiler/react-compiler': 'error', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be:
'eslint-plugin-react-compiler/react-compiler': 'error'If not, you will get the following error:
[Error] Request textDocument/diagnostic failed.
Message: Request textDocument/diagnostic failed with message: Key "rules": Key "react-compiler/react-compiler": Could not find plugin "react-compiler".
Code: -32603
[Error] Document pull failed for text document file:///.../eslint.config.mjs
Message: Request textDocument/diagnostic failed with message: Key "rules": Key "react-compiler/react-compiler": Could not find plugin "react-compiler".
Code: -32603There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's not how it works - check other plugin docs:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea @AnthonyLzq is right here
in flat config you can infer the plugin namespace in the plugins object ref here
in the example you shared the plugin namespace is react-x thats why rules are referred with react-x/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry @AnthonyLzq @harish-sethuraman I see what you mean now
I fixed it the more conventional way, by using 'react-compiler' as a key in the plugins object:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Sweet, thanks! |
| import reactCompiler from 'eslint-plugin-react-compiler' | ||
|
|
||
| export default [ | ||
| { | ||
| plugins: { | ||
| 'react-compiler': reactCompiler, | ||
| }, | ||
| rules: { | ||
| 'react-compiler/react-compiler': 'error', | ||
| }, | ||
| }, | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case this would be an accepted change, I actually tend to prefer:
- a separate
configsvariable (instead of an anonymous export) - usage of the ESLint
Linter.Config[]TS type with a JSDoc annotation
| import reactCompiler from 'eslint-plugin-react-compiler' | |
| export default [ | |
| { | |
| plugins: { | |
| 'react-compiler': reactCompiler, | |
| }, | |
| rules: { | |
| 'react-compiler/react-compiler': 'error', | |
| }, | |
| }, | |
| ] | |
| import reactCompiler from 'eslint-plugin-react-compiler' | |
| /** @type {import('eslint').Linter.Config[]} */ | |
| const configs = [ | |
| { | |
| plugins: { | |
| 'react-compiler': reactCompiler, | |
| }, | |
| rules: { | |
| 'react-compiler/react-compiler': 'error', | |
| }, | |
| }, | |
| ] | |
| export default configs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@poteto @harish-sethuraman oh lol too slow (thanks for the merge!)
in case this is a desirable change, I can open a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer leaving it off since this is more about personal preference. We just want the minimal config in the docs.
ESLint v8 is end-of-life and ESLint v9 uses flat config by default, so starting with this as a first example seems like the right option (https://x.com/karlhorky/status/1848758371127583015)
Also, fixed the ESLint brand name typos
cc @poteto