-
-
Notifications
You must be signed in to change notification settings - Fork 725
refactor(linter): extract duplicated is_jsx_fragment function to shared utils
#13093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(linter): extract duplicated is_jsx_fragment function to shared utils
#13093
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
is_jsx_fragment function to shared utils
- Extract duplicated `is_jsx_fragment` function from jsx_fragments and jsx_no_useless_fragment - Move function to utils/react.rs to eliminate code duplication - Update both rules to use shared utility function - Clean up unused imports in both rule files - All tests continue to pass Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
- Verified self-closing fragment handling is correct (already implemented) - Extracted duplicated is_jsx_fragment function to shared utils - All jsx-related tests passing (49/49) - Code properly formatted - Review comments from PR #12988 addressed Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
d84177e to
039f986
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR extracts a duplicated is_jsx_fragment function from two React linting rules to eliminate code duplication. The function identifies React fragments in both <Fragment> and <React.Fragment> forms.
- Extracted the shared
is_jsx_fragmentfunction toutils/react.rs - Updated both
jsx_fragmentsandjsx_no_useless_fragmentrules to use the shared utility - Removed duplicate implementations and cleaned up unused imports
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/oxc_linter/src/utils/react.rs |
Added the shared is_jsx_fragment function with documentation |
crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs |
Removed duplicate function and updated calls to use shared utility |
crates/oxc_linter/src/rules/react/jsx_fragments.rs |
Removed duplicate function, cleaned up imports, and updated calls to use shared utility |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
CodSpeed Instrumentation Performance ReportMerging #13093 will not alter performanceComparing Summary
|
|
@copilot update the code such that |
…s_jsx_fragment Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
Updated the code to import |
This PR addresses review comments from PR #12988 by extracting the duplicated
is_jsx_fragmentfunction that was present in bothjsx_fragments.rsandjsx_no_useless_fragment.rsrules.Changes Made
Code Deduplication
is_jsx_fragmentfunction from both React linting rulescrates/oxc_linter/src/utils/react.rsas a shared utilityjsx_fragmentsandjsx_no_useless_fragmentrules to use the shared functionSelf-Closing Fragment Handling
The review also mentioned handling self-closing fragments (e.g.,
<Fragment />). Upon investigation, this was already correctly implemented in the original code:Self-closing fragments cannot be converted to shorthand syntax (
<></>) and should not trigger the rule, which is the correct behavior already in place.Function Details
The extracted
is_jsx_fragmentfunction recognizes both forms of React fragments:<Fragment>(identifier reference)<React.Fragment>(member expression)Testing
jsx_fragmentsandjsx_no_useless_fragmentrules maintain their behaviorThis refactoring eliminates code duplication while maintaining full backward compatibility and correctness of both linting rules.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.