dillon1000/react

Commit

[eslint-plugin-react-hooks] Skip compilation for non-React files (#35589)

Add a fast heuristic to detect whether a file may contain React
components or hooks before running the full compiler. This avoids the
overhead of Babel AST parsing and compilation for utility files, config
files, and other non-React code.

The heuristic uses ESLint's already-parsed AST to check for functions
with React-like names at module scope:
- Capitalized functions: MyComponent, Button, App
- Hook pattern functions: useEffect, useState, useMyCustomHook

Files without matching function names are skipped and return an empty
result, which is cached to avoid re-checking for subsequent rules.

Also adds test coverage for the heuristic edge cases.
Browse files
Changed paths4 files
First-parent comparison
A packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRuleFlow-test.ts AddedM packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRuleTypescript-test.ts ModifiedM packages/eslint-plugin-react-hooks/jest.config.js ModifiedM packages/eslint-plugin-react-hooks/src/shared/RunReactCompiler.ts Modified
Patch

Files changed

Rendering syntax-highlighted changes…