-
-
Notifications
You must be signed in to change notification settings - Fork 794
fix(useReactFunctionComponents): handle class expressions with componentDidCatch #8102
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
Conversation
🦋 Changeset detectedLatest commit: 15951ba The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThe Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
crates/biome_js_analyze/tests/specs/style/useReactFunctionComponents/valid.jsx (1)
27-33: Good test case, but consider testing exported class expressions as well.The test validates the fix for non-exported class expressions. Consider adding another test case for exported class expressions to ensure comprehensive coverage:
export const ExportedErrorBoundary = class extends React.Component { componentDidCatch(error, errorInfo) {} render() { return this.props.children; } }crates/biome_js_analyze/src/lint/style/use_react_function_components.rs (1)
118-133: Fix works correctly, but consider extracting the duplicate member-checking logic.The logic correctly handles class expressions assigned to variables. However, the pattern for checking if a member is named "componentDidCatch" is now duplicated across three branches (lines 96-106, 109-116, and 123-130).
Consider extracting a helper function:
fn has_method_named(members: impl Iterator<Item = impl AstNode>, method_name: &str) -> bool { members.any(|member| { member .name() .ok() .flatten() .and_then(|name| name.name()) .is_some_and(|name| name.text() == method_name) }) }Then use it in all three branches:
JsClassDeclaration(js_class_declaration) => { has_method_named(js_class_declaration.members().iter(), "componentDidCatch") }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
crates/biome_js_analyze/tests/specs/style/useReactFunctionComponents/valid.jsx.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (3)
.changeset/fuzzy-worms-smell.md(1 hunks)crates/biome_js_analyze/src/lint/style/use_react_function_components.rs(2 hunks)crates/biome_js_analyze/tests/specs/style/useReactFunctionComponents/valid.jsx(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Bench (biome_js_formatter)
- GitHub Check: Bench (biome_js_parser)
- GitHub Check: Bench (biome_js_analyze)
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Documentation
- GitHub Check: Test Node.js API
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Check Dependencies
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: autofix
🔇 Additional comments (2)
crates/biome_js_analyze/src/lint/style/use_react_function_components.rs (1)
5-5: LGTM!Import is used correctly in the new match branch.
.changeset/fuzzy-worms-smell.md (1)
1-16: LGTM!The changeset clearly documents the fix with a relevant example. Patch version is appropriate for this bug fix.
CodSpeed Performance ReportMerging #8102 will not alter performanceComparing Summary
Footnotes
|
crates/biome_js_analyze/tests/specs/style/useReactFunctionComponents/valid.jsx.snap
Show resolved
Hide resolved
dyc3
left a comment
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.
Thank you!
Summary
Fixes #8027. The
useReactFunctionComponentsrule incorrectly flagged class components that implementcomponentDidCatchusing class expressions.Test Plan