Skip to content

[compiler] Surface all lint diagnostics instead of stopping at first validation error#575

Closed
everettbu wants to merge 1 commit into
mainfrom
fix/lint-mode-surface-all-diagnostics
Closed

[compiler] Surface all lint diagnostics instead of stopping at first validation error#575
everettbu wants to merge 1 commit into
mainfrom
fix/lint-mode-surface-all-diagnostics

Conversation

@everettbu

Copy link
Copy Markdown

Mirror of facebook/react#35857
Original author: sleitor


Summary

In lint mode (ESLint plugin), the compilation pipeline stops at the first validation error. For example, if validateHooksUsage finds an issue, subsequent validations like validateNoCapitalizedCalls never run, hiding additional lint errors from the user.

This PR changes the pipeline to use env.logErrors() instead of .unwrap() for early validations (hooks usage and capitalized calls) when in lint mode. These validations are purely diagnostic — they don't modify the HIR — so it's safe to continue the pipeline after logging their errors.

Before

A file with both a hooks violation and a capitalized-calls violation would only show the hooks error.

After

Both errors are surfaced to the user.

How did you test this change?

  • Added new test in Repro35394-test.ts that reproduces the issue from #35394
  • Updated existing PluginTest-test.ts to verify the newly surfaced diagnostics (the existing TODO comment 'actually return multiple diagnostics in this case' is now resolved)
  • All 33 ESLint plugin tests pass

Fixes #35394
Fixes #31545

…validation error

In lint mode (ESLint plugin), the compilation pipeline would stop at the
first validation error. For example, if `validateHooksUsage` found an
issue, subsequent validations like `validateNoCapitalizedCalls` would
never run, hiding additional lint errors from the user.

This changes the pipeline to use `env.logErrors()` instead of
`.unwrap()` for early validations (hooks usage and capitalized calls)
when in lint mode. These validations are purely diagnostic — they don't
modify the HIR — so it's safe to continue the pipeline after logging
their errors.

This fixes the issue where files with multiple types of lint violations
would only show the first category of error.

Fixes #35394
Fixes #31545
@greptile-apps

greptile-apps Bot commented Feb 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes the React Compiler ESLint plugin to surface all lint diagnostics from a function instead of stopping at the first validation error. Previously, validateHooksUsage and validateNoCapitalizedCalls used .unwrap() which throws on the first error, preventing subsequent validations from running. The fix switches to env.logErrors() in lint mode, matching the existing pattern used by other lint-only validations (validateNoDerivedComputationsInEffects_exp, validateNoSetStateInEffects, validateNoJSXInTryStatement, validateStaticComponents). Since these validations are purely diagnostic and don't modify the HIR, continuing the pipeline after logging errors is safe.

  • Changed Pipeline.ts to use env.logErrors() instead of .unwrap() for hooks usage and capitalized calls validations in lint mode
  • Widened logErrors parameter type from Result<void> to Result<unknown> to accept all validation return types
  • Added regression test (Repro35394-test.ts) reproducing the issue from #35394
  • Updated existing test to verify the newly surfaced second diagnostic, resolving a long-standing TODO

Confidence Score: 5/5

  • This PR is safe to merge — it only changes lint-mode behavior using an established pattern already used elsewhere in the same file.
  • The change is minimal, well-scoped, and follows an existing pattern (env.logErrors()) already used for other validations in the pipeline. The validations are purely diagnostic (they don't modify the HIR), so continuing after logging errors is safe. The type widening from void to unknown is backwards-compatible and appropriate. Both new and updated tests cover the changed behavior.
  • No files require special attention.

Important Files Changed

Filename Overview
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Pipeline.ts In lint mode, uses env.logErrors() instead of .unwrap() for validateHooksUsage and validateNoCapitalizedCalls, allowing the pipeline to continue and surface all diagnostics. Consistent with existing patterns for other lint-only validations in the same file.
compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts Widens logErrors parameter type from Result<void, CompilerError> to Result<unknown, CompilerError> to accommodate validation functions that may return different success types. Safe change since only the error path is used.
compiler/packages/eslint-plugin-react-compiler/tests/PluginTest-test.ts Removes resolved TODO comment and adds expected second diagnostic for the capitalized-calls validation, confirming the fix works for the existing multi-diagnostic test case.
compiler/packages/eslint-plugin-react-compiler/tests/Repro35394-test.ts New regression test for #35394 with two test cases verifying multiple violations (hooks usage + capitalized calls + static components) are all surfaced in lint mode.

Last reviewed commit: aac8052

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@everettbu

Copy link
Copy Markdown
Author

Upstream PR was closed or merged. Code is synced via branch mirror.

@everettbu everettbu closed this Feb 22, 2026
@everettbu
everettbu deleted the fix/lint-mode-surface-all-diagnostics branch February 22, 2026 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants