react/compiler/packages/eslint-plugin-react-compiler
lauren 4ab827b869
[compiler] Dedupe @babel/types (#32581)
Extracting portions of #32416 for easier review. This PR dedupes
@babel/types to resolve to 7.26.3, for compatibility in the root
workspace where eslint-plugin-react-hooks resides.

I also needed to update @babel/preset-typescript in snap.

The compiler changes in HIR and ReactiveScopes were needed due to types
changing. Notably, Babel [added support for optional chaining
assignment](https://github.com/babel/babel/pull/15751) (currently [Stage
1](https://github.com/tc39/proposal-optional-chaining-assignment)), so
in the latest versions of @babel/types, AssignmentExpression.left can
now also be of t.OptionalMemberExpression.

Given that this is in Stage 1, the compiler probably shouldn't support
this syntax, so this PR updates HIR to bailout with a TODO if there is a
non LVal on the lhs of an Assignment Expression.

There was also a small superficial SourceLocation change needed in
`InferReactiveScopeVariables` as Babel 8 changes were [accidentally
released in
7](https://github.com/babel/babel/issues/10746#issuecomment-2699146670).
It doesn't affect our analysis so it seems fine to just update with the
new properties.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32581).
* #32582
* __->__ #32581

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 17:02:10 -04:00
..
__tests__ [compiler] Surface unused opt out directives in eslint 2024-08-16 18:12:05 -04:00
src [compiler] Migrate compiler packages to tsup (#32550) 2025-03-07 16:41:55 -05:00
babel.config.js Compiler: unfork prettier config (#30205) 2024-07-18 17:00:24 -04:00
package.json [compiler] Dedupe @babel/types (#32581) 2025-03-12 17:02:10 -04:00
README.md docs(eslint-plugin-react-compiler): fix typo (#32149) 2025-01-22 16:59:50 +01:00
tsconfig.json [compiler] Migrate compiler packages to tsup (#32550) 2025-03-07 16:41:55 -05:00
tsup.config.ts [compiler] Migrate compiler packages to tsup (#32550) 2025-03-07 16:41:55 -05:00

eslint-plugin-react-compiler

ESLint plugin surfacing problematic React code found by the React compiler.

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-react-compiler:

npm install eslint-plugin-react-compiler --save-dev

Usage

Flat config

Edit your eslint 8+ config (for example eslint.config.mjs) with the recommended configuration:

+ import reactCompiler from "eslint-plugin-react-compiler"
import react from "eslint-plugin-react"

export default [
    // Your existing config
    { ...pluginReact.configs.flat.recommended, settings: { react: { version: "detect" } } },
+   reactCompiler.configs.recommended    
]

Legacy config (.eslintrc)

Add react-compiler to the plugins section of your configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "react-compiler"
    ]
}

Then configure the rules you want to use under the rules section.

{
    "rules": {
        "react-compiler/react-compiler": "error"
    }
}

Rules

TODO: Run eslint-doc-generator to generate the rules list.