Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/fuzzy-worms-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@biomejs/biome": patch
---

Fixed [#8027](https://github.com/biomejs/biome/issues/8027). [`useReactFunctionComponents`](https://biomejs.dev/linter/rules/use-react-function-components/) no longer reports class components that implement `componentDidCatch` using class expressions.

The rule now correctly recognizes error boundaries defined as class expressions:
```jsx
const ErrorBoundary = class extends Component {
componentDidCatch(error, info) {}

render() {
return this.props.children;
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use biome_analyze::{
Ast, Rule, RuleDiagnostic, RuleDomain, RuleSource, context::RuleContext, declare_lint_rule,
};
use biome_console::markup;
use biome_js_syntax::AnyJsExpression;
use biome_rowan::{AstNode, AstNodeList};
use biome_rule_options::use_react_function_components::UseReactFunctionComponentsOptions;

Expand Down Expand Up @@ -114,6 +115,22 @@ fn has_component_did_catch(node: &AnyPotentialReactComponentDeclaration) -> bool
.is_some_and(|name| name.text() == "componentDidCatch")
})
}
JsVariableDeclarator(variable_declarator) => variable_declarator
.initializer()
.and_then(|initializer| initializer.expression().ok())
.is_some_and(|expression| {
if let AnyJsExpression::JsClassExpression(class_expression) = &expression {
return class_expression.members().iter().any(|member| {
member
.name()
.ok()
.flatten()
.and_then(|name| name.name())
.is_some_and(|name| name.text() == "componentDidCatch")
});
}
false
}),
_ => false,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ export default class Bar extends React.Component {
return <div>This is a class component with error handling.</div>;
}
}

const ErrorBoundary = class extends React.Component {
componentDidCatch(error, errorInfo) {}

render() {
return this.props.children;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ export default class Bar extends React.Component {
}
}

const ErrorBoundary = class extends React.Component {
componentDidCatch(error, errorInfo) {}

render() {
return this.props.children;
}
}

```