Skip to content

Commit e628e5d

Browse files
authored
Add ESLint flat config example, fix ESLint name (#7246)
* Add ESLint flat config example, fix ESLint name * Use official terminology * Fix key
1 parent 1bda70a commit e628e5d

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/content/learn/react-compiler.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ These docs are still a work in progress. More documentation is available in the
1313
<YouWillLearn>
1414

1515
* Getting started with the compiler
16-
* Installing the compiler and eslint plugin
16+
* Installing the compiler and ESLint plugin
1717
* Troubleshooting
1818

1919
</YouWillLearn>
@@ -26,7 +26,7 @@ The latest Beta release can be found with the `@beta` tag, and daily experimenta
2626

2727
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.
2828

29-
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.
29+
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.
3030

3131
The compiler is currently released as `beta`, and is available to try out on React 17+ apps and libraries. To install the Beta:
3232

@@ -126,29 +126,46 @@ In addition to these docs, we recommend checking the [React Compiler Working Gro
126126

127127
### Installing eslint-plugin-react-compiler {/*installing-eslint-plugin-react-compiler*/}
128128

129-
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.
129+
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.
130130

131131
<TerminalBlock>
132132
npm install -D eslint-plugin-react-compiler@beta
133133
</TerminalBlock>
134134

135-
Then, add it to your eslint config:
135+
Then, add it to your ESLint config:
136+
137+
```js
138+
import reactCompiler from 'eslint-plugin-react-compiler'
139+
140+
export default [
141+
{
142+
plugins: {
143+
'react-compiler': reactCompiler,
144+
},
145+
rules: {
146+
'react-compiler/react-compiler': 'error',
147+
},
148+
},
149+
]
150+
```
151+
152+
Or, in the deprecated eslintrc config format:
136153

137154
```js
138155
module.exports = {
139156
plugins: [
140157
'eslint-plugin-react-compiler',
141158
],
142159
rules: {
143-
'react-compiler/react-compiler': "error",
160+
'react-compiler/react-compiler': 'error',
144161
},
145162
}
146163
```
147164

148-
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.
165+
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.
149166

150167
<Note>
151-
**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.
168+
**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.
152169
</Note>
153170

154171
### 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
333350
[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.
334351

335352
### Something is not working after compilation {/*something-is-not-working-after-compilation*/}
336-
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.
353+
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.
337354

338355
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.
339356

340-
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).
357+
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).
341358

342359
```js {2}
343360
function SuspiciousComponent() {

0 commit comments

Comments
 (0)