-
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ These docs are still a work in progress. More documentation is available in the | |
| <YouWillLearn> | ||
|
|
||
| * Getting started with the compiler | ||
| * Installing the compiler and eslint plugin | ||
| * Installing the compiler and ESLint plugin | ||
| * Troubleshooting | ||
|
|
||
| </YouWillLearn> | ||
|
|
@@ -26,7 +26,7 @@ The latest Beta release can be found with the `@beta` tag, and daily experimenta | |
|
|
||
| React Compiler is a new compiler that we've open sourced to get early feedback from the community. It is a build-time only tool that automatically optimizes your React app. It works with plain JavaScript, and understands the [Rules of React](/reference/rules), so you don't need to rewrite any code to use it. | ||
|
|
||
| The compiler also includes an [eslint plugin](#installing-eslint-plugin-react-compiler) that surfaces the analysis from the compiler right in your editor. **We strongly recommend everyone use the linter today.** The linter does not require that you have the compiler installed, so you can use it even if you are not ready to try out the compiler. | ||
| The compiler also includes an [ESLint plugin](#installing-eslint-plugin-react-compiler) that surfaces the analysis from the compiler right in your editor. **We strongly recommend everyone use the linter today.** The linter does not require that you have the compiler installed, so you can use it even if you are not ready to try out the compiler. | ||
|
|
||
| The compiler is currently released as `beta`, and is available to try out on React 17+ apps and libraries. To install the Beta: | ||
|
|
||
|
|
@@ -126,29 +126,46 @@ In addition to these docs, we recommend checking the [React Compiler Working Gro | |
|
|
||
| ### Installing eslint-plugin-react-compiler {/*installing-eslint-plugin-react-compiler*/} | ||
|
|
||
| React Compiler also powers an eslint plugin. The eslint plugin can be used **independently** of the compiler, meaning you can use the eslint plugin even if you don't use the compiler. | ||
| React Compiler also powers an ESLint plugin. The ESLint plugin can be used **independently** of the compiler, meaning you can use the ESLint plugin even if you don't use the compiler. | ||
|
|
||
| <TerminalBlock> | ||
| npm install -D eslint-plugin-react-compiler@beta | ||
| </TerminalBlock> | ||
|
|
||
| Then, add it to your eslint config: | ||
| Then, add it to your ESLint config: | ||
|
|
||
| ```js | ||
| import reactCompiler from 'eslint-plugin-react-compiler' | ||
|
|
||
| export default [ | ||
| { | ||
| plugins: { | ||
| 'eslint-plugin-react-compiler': reactCompiler, | ||
| }, | ||
| rules: { | ||
| 'react-compiler/react-compiler': 'error', | ||
karlhorky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| ] | ||
| ``` | ||
|
|
||
| Or, in the deprecated eslintrc config format: | ||
|
|
||
| ```js | ||
| module.exports = { | ||
| plugins: [ | ||
| 'eslint-plugin-react-compiler', | ||
| ], | ||
| rules: { | ||
| 'react-compiler/react-compiler': "error", | ||
| 'react-compiler/react-compiler': 'error', | ||
|
Comment on lines
-143
to
+160
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made the quote style here consistent with the other quotes |
||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| The eslint plugin will display any violations of the rules of React in your editor. When it does this, it means that the compiler has skipped over optimizing that component or hook. This is perfectly okay, and the compiler can recover and continue optimizing other components in your codebase. | ||
| The ESLint plugin will display any violations of the rules of React in your editor. When it does this, it means that the compiler has skipped over optimizing that component or hook. This is perfectly okay, and the compiler can recover and continue optimizing other components in your codebase. | ||
|
|
||
| <Note> | ||
| **You don't have to fix all eslint violations straight away.** You can address them at your own pace to increase the amount of components and hooks being optimized, but it is not required to fix everything before you can use the compiler. | ||
| **You don't have to fix all ESLint violations straight away.** You can address them at your own pace to increase the amount of components and hooks being optimized, but it is not required to fix everything before you can use the compiler. | ||
| </Note> | ||
|
|
||
| ### Rolling out the compiler to your codebase {/*using-the-compiler-effectively*/} | ||
|
|
@@ -333,11 +350,11 @@ React Compiler can verify many of the Rules of React statically, and will safely | |
| [React Devtools](/learn/react-developer-tools) (v5.0+) has built-in support for React Compiler and will display a "Memo ✨" badge next to components that have been optimized by the compiler. | ||
|
|
||
| ### Something is not working after compilation {/*something-is-not-working-after-compilation*/} | ||
| If you have eslint-plugin-react-compiler installed, the compiler will display any violations of the rules of React in your editor. When it does this, it means that the compiler has skipped over optimizing that component or hook. This is perfectly okay, and the compiler can recover and continue optimizing other components in your codebase. **You don't have to fix all eslint violations straight away.** You can address them at your own pace to increase the amount of components and hooks being optimized. | ||
| If you have eslint-plugin-react-compiler installed, the compiler will display any violations of the rules of React in your editor. When it does this, it means that the compiler has skipped over optimizing that component or hook. This is perfectly okay, and the compiler can recover and continue optimizing other components in your codebase. **You don't have to fix all ESLint violations straight away.** You can address them at your own pace to increase the amount of components and hooks being optimized. | ||
|
|
||
| Due to the flexible and dynamic nature of JavaScript however, it's not possible to comprehensively detect all cases. Bugs and undefined behavior such as infinite loops may occur in those cases. | ||
|
|
||
| If your app doesn't work properly after compilation and you aren't seeing any eslint errors, the compiler may be incorrectly compiling your code. To confirm this, try to make the issue go away by aggressively opting out any component or hook you think might be related via the [`"use no memo"` directive](#opt-out-of-the-compiler-for-a-component). | ||
| If your app doesn't work properly after compilation and you aren't seeing any ESLint errors, the compiler may be incorrectly compiling your code. To confirm this, try to make the issue go away by aggressively opting out any component or hook you think might be related via the [`"use no memo"` directive](#opt-out-of-the-compiler-for-a-component). | ||
|
|
||
| ```js {2} | ||
| function SuspiciousComponent() { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
If not, you will get the following 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.
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-xthats why rules are referred withreact-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 thepluginsobject: