Repository navigation
feat(linter/react): implement react-compiler rule - #23202
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a nursery
react/react-compilerrule that runs the React Compiler (oxc_react_compiler) in lint-only mode and reports Rules of React violations: conditional hook calls, setState during render, ref access during render, mutation errors, etc.Rule
run_oncerule callingoxc_react_compiler::lint()on the program; the compiler's own prefilter skips files with no React-like functions.eslint-plugin-react-compiler(COMPILER_OPTIONSin itsRunReactCompiler.ts):lintoutput mode plus the validations the plugin force-enables (impure functions, capitalized calls, JSX in try, static components, setState in effects, etc.).reportAllBailouts.$FlowFixMe[react-rule-hook]/$FlowFixMe[react-rule-unsafe-ref]comment are dropped, while other diagnostics in the same function still surface.Tests
All test cases from
eslint-plugin-react-compiler/__tests__(MIT) are ported, covering hooks order, capitalized calls, impure calls in render, JSX in try/catch, ref access in render, useMemo diagnostics, useState mutation (TS),'use memo'/'use no forget'directives, and Flow suppressions. The only case not ported is "Basic example with component syntax", which uses Flow's experimentalcomponentdeclaration syntax that oxc does not parse.RustBackendComparison-test.tsreplicates the same cases for backend comparison, so it adds no new ones. Every diagnostic message and location in the snapshot matches the upstream assertions.Diagnostics
oxc_react_compilerdiagnostics previously had no spans. They now carry labeled spans built from the compiler's source locations (byte offsets flow through from oxc spans):detail.loc→ sub-detail locations with their messages (e.g. "Found setState() in render") → enclosing function as fallback. Long descriptions moved from the message intohelp. This makes code frames andoxlint-disabledirectives work.Example output:
🤖 Generated with Claude Code