react/compiler/packages/eslint-plugin-react-compiler
Joseph Savona 7f5ea1bf67
[compiler] More useMemo validation (#34868)
Two additional validations for useMemo:
* Disallow reassigning to values declared outside the useMemo callback
(always on)
* Disallow unused useMemo calls (part of the validateNoVoidUseMemo
feature flag, which in turn is off by default)

We should probably enable this flag though!

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34868).
* #34855
* #34882
* __->__ #34868
2025-10-16 13:05:18 -07:00
..
__tests__ [compiler] More useMemo validation (#34868) 2025-10-16 13:05:18 -07:00
src [compiler] Setup RecommendedLatest preset (#34782) 2025-10-08 15:45:22 -04:00
babel.config.js [compiler] Remove @babel/plugin-proposal-private-methods (#34715) 2025-10-03 09:13:55 -07:00
package.json [compiler] improve zod v3 backwards compat (#34877) 2025-10-16 09:46:55 -07: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] improve zod v3 backwards compat (#34877) 2025-10-16 09:46:55 -07: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.