Skip to content

fix(eslint-plugin-react-hooks): use messageId instead of inline message in rule reports#654

Open
everettbu wants to merge 1 commit into
mainfrom
fix/eslint-hooks-vscode-messageId
Open

fix(eslint-plugin-react-hooks): use messageId instead of inline message in rule reports#654
everettbu wants to merge 1 commit into
mainfrom
fix/eslint-hooks-vscode-messageId

Conversation

@everettbu

Copy link
Copy Markdown

Mirror of facebook/react#35955
Original author: fresh3nough


Summary

Converts both RulesOfHooks and ExhaustiveDeps rules to use ESLint messageId API with meta.messages instead of inline message strings in context.report() calls. This follows ESLint best practices and fixes issues with the VS Code ESLint extension not showing rule codes in the Problems pane, which also causes other ESLint rules in the same file to break.

How did you test this change?

All 5082 existing tests pass (4 test suites across ESLint v7 and v9 with multiple parsers). TypeScript typecheck passes.

Fixes: react/react#35897

@greptile-apps

greptile-apps Bot commented Mar 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR migrates the RulesOfHooks and ExhaustiveDeps ESLint rules from inline message strings in context.report() calls to the messageId API with centralized meta.messages definitions. This follows ESLint best practices and fixes an issue where the VS Code ESLint extension couldn't properly show rule codes in the Problems pane.

  • RulesOfHooks.ts: Adds 10 message definitions to meta.messages, converts all context.report() calls to use messageId + data, and removes the now-unused useEffectEventError helper function.
  • ExhaustiveDeps.ts: Adds 17 message definitions to meta.messages, converts all reportProblem() calls to use messageId + data, and removes the unused getUnknownDependenciesMessage helper.
  • ESLintRulesOfHooks-test.js: Updates all test helper functions (conditionalError, loopError, functionError, etc.) and inline error assertions to match errors using messageId + data instead of rendered message strings.
  • The ExhaustiveDeps test file was not updated in this PR but remains compatible since ESLint's RuleTester can match errors by rendered message string even when the rule uses messageId.

Confidence Score: 5/5

  • This PR is a safe, mechanical refactor that only changes how ESLint rule messages are structured without altering any logic or message content.
  • The conversion from inline message to messageId is purely structural. All message templates exactly match their original inline counterparts. The reportProblem wrapper in ExhaustiveDeps correctly passes messageId and data through to context.report(). All messageIds are properly defined and referenced. The test updates align with the implementation changes. No behavioral changes are introduced.
  • No files require special attention.

Important Files Changed

Filename Overview
packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts Converts all context.report() calls from inline message to messageId + data. Removes the now-unused useEffectEventError helper. All 10 messageIds are properly defined in meta.messages and correctly referenced with appropriate template variables.
packages/eslint-plugin-react-hooks/src/rules/ExhaustiveDeps.ts Converts all reportProblem() calls from inline message to messageId + data. All 17 messageIds are properly defined in meta.messages. The reportProblem wrapper correctly passes the full descriptor (including messageId and data) through to context.report(). Removes unused getUnknownDependenciesMessage helper.
packages/eslint-plugin-react-hooks/tests/ESLintRulesOfHooks-test.js Updates all test helper functions and inline error assertions to use messageId + data format instead of message strings, aligning with the rule implementation changes.

Last reviewed commit: 7cbefbd

…ge in rule reports

Convert both RulesOfHooks and ExhaustiveDeps rules to use ESLint's
messageId API with meta.messages instead of inline message strings in
context.report() calls. This follows ESLint best practices and fixes
issues with the VS Code ESLint extension not showing rule codes in the
Problems pane, which also causes other ESLint rules in the same file
to break.

Fixes: react/react#35897
@everettbu
everettbu force-pushed the fix/eslint-hooks-vscode-messageId branch from b9f7e2f to 7cbefbd Compare March 5, 2026 00:40
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.

[Compiler Bug]: eslint-plugin-react-hooks breaks the VS Code ESLint extension

2 participants