-
-
Notifications
You must be signed in to change notification settings - Fork 668
feat(linter): impl only-export-components to react rules #14122
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
base: main
Are you sure you want to change the base?
feat(linter): impl only-export-components to react rules #14122
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. |
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 implements the only-export-components
rule for React linter rules, ensuring modules only export React components and HMR-safe items to support Fast Refresh functionality.
- Adds comprehensive validation for React component exports and Fast Refresh compatibility
- Implements configurable options for allowed export names, constant exports, custom HOCs, and JS file checking
- Provides detailed diagnostics for various violation scenarios including anonymous components, mixed exports, and React contexts
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
File | Description |
---|---|
crates/oxc_linter/src/rules/react/only_export_components.rs |
Complete implementation of the only-export-components rule with export analysis, component detection, and diagnostic reporting |
crates/oxc_linter/src/snapshots/react_only_export_components.snap |
Test snapshots showing expected diagnostic outputs for various rule violations |
crates/oxc_linter/src/rules.rs |
Module registration adding the new rule to the linter's rule set |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
CodSpeed Instrumentation Performance ReportMerging #14122 will not alter performanceComparing Summary
Footnotes
|
d8d2835
to
dbdbe75
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
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
b230010
to
d059a20
Compare
We've addressed the feedback you provided! |
fn should_scan(f: &str, check_js: bool) -> bool { | ||
use std::path::Path; | ||
Path::new(f).extension().is_some_and(|ext| ext.eq_ignore_ascii_case("tsx")) | ||
|| Path::new(f).extension().is_some_and(|ext| ext.eq_ignore_ascii_case("jsx")) | ||
|| (check_js | ||
&& Path::new(f).extension().is_some_and(|ext| ext.eq_ignore_ascii_case("js"))) | ||
} |
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.
fn should_scan(f: &str, check_js: bool) -> bool { | |
use std::path::Path; | |
Path::new(f).extension().is_some_and(|ext| ext.eq_ignore_ascii_case("tsx")) | |
|| Path::new(f).extension().is_some_and(|ext| ext.eq_ignore_ascii_case("jsx")) | |
|| (check_js | |
&& Path::new(f).extension().is_some_and(|ext| ext.eq_ignore_ascii_case("js"))) | |
} | |
fn should_scan(f: &str, check_js: bool) -> bool { | |
use std::path::Path; | |
let ext = Path::new(f).extension().and_then(|e| e.to_str()); | |
matches!(ext, Some(e) if e.eq_ignore_ascii_case("tsx") || e.eq_ignore_ascii_case("jsx")) | |
|| (check_js && matches!(ext, Some(e) if e.eq_ignore_ascii_case("js"))) | |
} |
we can reduce the number of Path:;new
calls by restructuring this slightly
d059a20
to
3a41415
Compare
Summary
close: #12386
I re-implemented only-export-components rule for react.
originals: