This document covers the 27 React Compiler rules integrated into eslint-plugin-react-hooks, providing advanced static analysis for React applications with performance optimization and enhanced code quality validation.
React Compiler rules are automatically imported from babel-plugin-react-compiler and provide static analysis beyond basic Hooks validation. These rules help optimize React applications by enforcing patterns that work well with React's compiler optimizations.
// React Compiler rule integration
import { allRules, recommendedRules, mapErrorSeverityToESlint } from './shared/ReactCompiler';
const compilerRules = Object.fromEntries(
Object.entries(allRules).map(([name, config]) => [name, config.rule])
);The React Compiler ESLint plugin imports 26 core rules from babel-plugin-react-compiler via the LintRules export, plus one additional rule (no-unused-directives) for a total of 27 rules.
These rules are included in the recommended configuration and focus on core React patterns and performance.
component-hook-factories (Error severity, recommended)const componentHookFactoriesRule: Rule.RuleModule;config (Error severity, recommended)const configRule: Rule.RuleModule;error-boundaries (Error severity, recommended)const errorBoundariesRule: Rule.RuleModule;gating (Error severity, recommended)const gatingRule: Rule.RuleModule;globals (Error severity, recommended)const globalsRule: Rule.RuleModule;immutability (Error severity, recommended)const immutabilityRule: Rule.RuleModule;incompatible-library (Warning severity, recommended)const incompatibleLibraryRule: Rule.RuleModule;no-unused-directives (Error severity, recommended)const noUnusedDirectivesRule: Rule.RuleModule;preserve-manual-memoization (Error severity, recommended)const preserveManualMemoizationRule: Rule.RuleModule;purity (Error severity, recommended)const purityRule: Rule.RuleModule;refs (Error severity, recommended)const refsRule: Rule.RuleModule;useRef() usageset-state-in-effect (Error severity, recommended)const setStateInEffectRule: Rule.RuleModule;set-state-in-render (Error severity, recommended)const setStateInRenderRule: Rule.RuleModule;static-components (Error severity, recommended)const staticComponentsRule: Rule.RuleModule;unsupported-syntax (Warning severity, recommended)const unsupportedSyntaxRule: Rule.RuleModule;use-memo (Error severity, recommended)const useMemoRule: Rule.RuleModule;useMemo() docs for more informationThese rules are available but not included in the recommended configuration.
automatic-effect-dependencies (Error severity, not recommended)const automaticEffectDependenciesRule: Rule.RuleModule;capitalized-calls (Error severity, not recommended)const capitalizedCallsRule: Rule.RuleModule;fbt (Error severity, not recommended)const fbtRule: Rule.RuleModule;fire (Error severity, not recommended)const fireRule: Rule.RuleModule;firehooks (Error severity, not recommended)const hooksRule: Rule.RuleModule;invariant (Error severity, not recommended)const invariantRule: Rule.RuleModule;memoized-effect-dependencies (Error severity, not recommended)const memoizedEffectDependenciesRule: Rule.RuleModule;no-deriving-state-in-effects (Error severity, not recommended)const noDeriveStateInEffectsRule: Rule.RuleModule;rule-suppression (Error severity, not recommended)const ruleSuppressionRule: Rule.RuleModule;syntax (Error severity, not recommended)const syntaxRule: Rule.RuleModule;todo (Hint severity, not recommended)const todoRule: Rule.RuleModule;All React Compiler rules support configuration through ESLint rule options:
interface CompilerRuleOptions {
[key: string]: any; // Validated at runtime with zod
}React Compiler error severities map to ESLint severities:
function mapErrorSeverityToESlint(severity: ErrorSeverity): Linter.StringSeverity {
switch (severity) {
case ErrorSeverity.Error: return 'error';
case ErrorSeverity.Warning: return 'warn';
case ErrorSeverity.Hint:
case ErrorSeverity.Off: return 'off';
}
}{
"rules": {
"react-hooks/immutability": "error",
"react-hooks/set-state-in-render": "error",
"react-hooks/preserve-manual-memoization": "warn"
}
}{
"rules": {
"react-hooks/config": ["error", {
"gating": true,
"environment": "development"
}]
}
}{
"rules": {
"react-hooks/unsupported-syntax": "off",
"react-hooks/incompatible-library": "warn"
}
}incompatible-library, unsupported-syntax)todo)The rules cover areas including hooks validation, component purity, state management, effect dependencies, memoization preservation, and React-specific best practices for optimal compiler performance.