fix(component-hook-factories): exclude HOC patterns and test mocks#1652
Merged
Rel1cx merged 4 commits intoRel1cx:mainfrom Mar 30, 2026
Merged
Conversation
- Bump eslint-plugin-unicorn to ^64.0.0 - Add @eslint-react/kit as a workspace dependency in apps/website - Normalize Markdown tables in core docs for consistent formatting - Update pnpm-lock.yaml to link the workspace kit
…lbacks from false positives The rule now correctly handles two common false-positive scenarios: 1. Higher Order Components (HOCs) that take a component as parameter (detected by PascalCase parameter name or ComponentType annotation) are no longer flagged, since the HOC definition itself is a valid React pattern. 2. Component definitions inside vi.mock() and jest.mock() callbacks are no longer flagged, since test mocks are not runtime code. Fixes Rel1cx#1632 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@zerone0x is attempting to deploy a commit to the Rel1cx's projects Team on Vercel. A member of the Team first needs to authorize it. |
da55aa7 to
8a4396f
Compare
Owner
Signed-off-by: REL1CX <solarflarex@qq.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the component-hook-factories ESLint rule to reduce false positives by excluding common Higher-Order Component (HOC) patterns and ignoring React component definitions created inside test mock factories.
Changes:
- Add AST utilities to detect
jest.mockand unifyvi.mock/jest.mockcallback detection viaisTestMockCallback. - Update
component-hook-factoriesto skip reporting components defined inside HOCs and insidevi.mock/jest.mockcallbacks. - Extend the rule spec with new valid cases covering HOC patterns and mock callbacks.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/utilities/ast/src/pattern-vitest-mock.ts | Adds jest.mock + shared test-mock callback detection helpers. |
| packages/plugins/eslint-plugin-react-x/src/rules/component-hook-factories/component-hook-factories.ts | Skips reports for nested components inside detected HOCs and test mock callbacks. |
| packages/plugins/eslint-plugin-react-x/src/rules/component-hook-factories/component-hook-factories.spec.ts | Adds valid test cases for HOCs and vi.mock/jest.mock callback scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...plugins/eslint-plugin-react-x/src/rules/component-hook-factories/component-hook-factories.ts
Outdated
Show resolved
Hide resolved
…k-factories/component-hook-factories.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: REL1CX <solarflarex@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WrappedComponent) orComponentType/FCtype annotations, and skips reporting components defined inside them.vi.mock()andjest.mock()callbacks, which are test-only code and should not be flagged.isJestMockCallbackandisTestMockCallbackutilities alongside the existingisViMockCallback.Fixes #1666, Fixes #1667
Test plan
vitest runon the spec file)withBorder(WrappedComponent)) is now validwithLoading(BaseComponent)) is now validvi.mock()component mocks are now validjest.mock()component mocks are now valid🤖 Generated with Claude Code