Skip to content

docs(eslint-plugin-react-hooks): warn about regex matching in additionalHooks#36096

Open
MorikawaSouma wants to merge 2 commits intofacebook:mainfrom
MorikawaSouma:fix/eslint-plugin-docs-regex-warning
Open

docs(eslint-plugin-react-hooks): warn about regex matching in additionalHooks#36096
MorikawaSouma wants to merge 2 commits intofacebook:mainfrom
MorikawaSouma:fix/eslint-plugin-docs-regex-warning

Conversation

@MorikawaSouma
Copy link

Summary

This PR improves the documentation for the additionalHooks option in eslint-plugin-react-hooks by adding a warning about regex matching behavior and providing a better example.

Problem

The additionalHooks option uses regex matching to identify custom hooks that should have their dependencies validated. However, the example regex in the documentation can match more than intended:

Example from docs: (useMyCustomHook|useMyOtherCustomHook)

Unintended matches:

  • useMyCustomHook - intended match
  • useMyCustomHook2 - unintended match
  • useMyOtherCustomHookTest - unintended match

This issue was discovered by WordPress Gutenberg when they used the same pattern and encountered bugs due to unintended matches (see WordPress/gutenberg#61598).

Issue: Fixes #29045

Solution

Added a warning to the documentation explaining this behavior and provided an example using word boundaries (\b) to ensure exact matches:

additionalHooks: "\\b(useMyCustomHook|useMyOtherCustomHook)\\b"

This pattern will only match:

  • useMyCustomHook - exact match
  • useMyOtherCustomHook - exact match
  • useMyCustomHook2 - no match (desired behavior)

Testing

  • ✅ Documentation change only, no code modifications
  • ✅ Follows existing documentation format and style
  • ✅ Provides actionable guidance for users

Impact

This documentation improvement will help users avoid a common pitfall when configuring additionalHooks, preventing bugs in their applications.


This is a documentation-only change with no functional impact on the plugin's behavior.

The profiling documentation links in DevTools were pointing to the
legacy reactjs.org domain via fb.me short URLs. Updated all references
to point to the current react.dev documentation.

Fixes facebook#31878

Changed:
- ProfilingNotSupported.js: fb.me/react-devtools-profiling → react.dev/reference/profiler
- NoProfilingData.js: fb.me/react-devtools-profiling → react.dev/reference/profiler
- TimelineNotSupported.js: fb.me/react-devtools-profiling → react.dev/reference/profiler

The old reactjs.org/link/profiling URL redirects to an outdated site
that displays a banner stating it's no longer updated.
…nalHooks

The additionalHooks option uses regex matching which can catch more
than intended. The example regex '(useMyCustomHook|useMyOtherCustomHook)'
would match 'useMyCustomHook2' and 'useMyOtherCustomHookTest' which
may not be the desired behavior.

Added a warning and example with word boundaries to help users avoid
this pitfall.

Fixes facebook#29045

This issue was reported when WordPress Gutenberg used the same regex
pattern and encountered unintended matches.
@meta-cla meta-cla bot added the CLA Signed label Mar 19, 2026
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.

Bug: eslint-plugin-react-hooks documentation might be misleading

1 participant