Skip to content

Commit b0b1f18

Browse files
authoredMar 13, 2025··
refactor(linter): Remove if let nesting from nextjs-no-async-client-component (#9764)
This PR just removes if lets so there is less nesting and better readability.
1 parent 6c11740 commit b0b1f18

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed
 

‎crates/oxc_linter/src/rules/nextjs/no_async_client_component.rs

+36-33
Original file line numberDiff line numberDiff line change
@@ -63,43 +63,46 @@ impl Rule for NoAsyncClientComponent {
6363
}
6464

6565
// async function MyComponent() {...}; export default MyComponent;
66-
if let ExportDefaultDeclarationKind::Identifier(export_default_id) =
66+
let ExportDefaultDeclarationKind::Identifier(export_default_id) =
6767
&export_default_decl.declaration
68-
{
69-
let Some(decl) = get_declaration_of_variable(export_default_id, ctx) else {
70-
continue;
71-
};
68+
else {
69+
continue;
70+
};
71+
let Some(decl) = get_declaration_of_variable(export_default_id, ctx) else {
72+
continue;
73+
};
7274

73-
if let AstKind::Function(func) = decl.kind() {
74-
if func.r#async
75-
&& func
76-
.id
77-
.as_ref()
78-
// `func.id.name` MUST be > 0 chars
79-
.is_some_and(|v| v.name.chars().next().unwrap().is_uppercase())
80-
{
81-
ctx.diagnostic(no_async_client_component_diagnostic(
82-
func.id.as_ref().unwrap().span,
83-
));
84-
}
75+
if let AstKind::Function(func) = decl.kind() {
76+
if func.r#async
77+
&& func
78+
.id
79+
.as_ref()
80+
// `func.id.name` MUST be > 0 chars
81+
.is_some_and(|v| v.name.chars().next().unwrap().is_uppercase())
82+
{
83+
ctx.diagnostic(no_async_client_component_diagnostic(
84+
func.id.as_ref().unwrap().span,
85+
));
8586
}
87+
}
88+
89+
let AstKind::VariableDeclarator(var_declarator) = decl.kind() else {
90+
continue;
91+
};
8692

87-
if let AstKind::VariableDeclarator(var_declarator) = decl.kind() {
88-
if let BindingPatternKind::BindingIdentifier(binding_ident) =
89-
&var_declarator.id.kind
90-
{
91-
// `binding_ident.name` MUST be > 0 chars
92-
if binding_ident.name.chars().next().unwrap().is_uppercase() {
93-
if let Some(Expression::ArrowFunctionExpression(arrow_expr)) =
94-
&var_declarator.init
95-
{
96-
if arrow_expr.r#async {
97-
ctx.diagnostic(no_async_client_component_diagnostic(
98-
binding_ident.span,
99-
));
100-
}
101-
}
102-
}
93+
let BindingPatternKind::BindingIdentifier(binding_ident) = &var_declarator.id.kind
94+
else {
95+
continue;
96+
};
97+
// `binding_ident.name` MUST be > 0 chars
98+
if binding_ident.name.chars().next().unwrap().is_uppercase() {
99+
if let Some(Expression::ArrowFunctionExpression(arrow_expr)) =
100+
&var_declarator.init
101+
{
102+
if arrow_expr.r#async {
103+
ctx.diagnostic(no_async_client_component_diagnostic(
104+
binding_ident.span,
105+
));
103106
}
104107
}
105108
}

0 commit comments

Comments
 (0)
Please sign in to comment.