react/compiler/packages/eslint-plugin-react-compiler
Lauren Tan cf7d895db6 [compiler:eslint] Fix false positive with TS type param syntax
Previously we would attempt to parse code in the eslint plugin with the
HermesParser first as it can handle some TS syntax. However, this was
leading to a mis-parse of React hook calls with type params (eg,
`useRef<null>()` as a BinaryExpression rather than a CallExpression with
a type param. This triggered our validation that Hooks should not be
used as normal values.

To fix this, we now try to parse with the babel parser (with TS support)
for filenames that end with ts/tsx, and fallback to HermesParser for
regular JS files.

ghstack-source-id: 5b7231031c
Pull Request resolved: https://github.com/facebook/react/pull/29081
2024-05-15 15:44:21 -07:00
..
__tests__ [compiler:eslint] Fix false positive with TS type param syntax 2024-05-15 15:44:21 -07:00
src [compiler:eslint] Fix false positive with TS type param syntax 2024-05-15 15:44:21 -07:00
babel.config.js Rename eslint-plugin-react-forget to eslint-plugin-react-compiler 2024-01-16 17:36:37 -05:00
package.json Add a main field to eslint-plugin-react-compiler, fixes #29068. (#29072) 2024-05-15 17:02:20 -04:00
README.md Rename eslint-plugin-react-forget to eslint-plugin-react-compiler 2024-01-16 17:36:37 -05:00
rollup.config.js Standardize on banner2 plugin 2024-04-02 12:13:41 -04:00
tsconfig.json Remove comments in builds 2024-04-02 10:32:24 -04: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

Add react-compiler to the plugins section of your .eslintrc 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/rule-name": 2
    }
}

Rules

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