Skip to content

Commit 42738f0

Browse files
authored
refactor(linter): shorten code of match arms (#11389)
Less code is always better :)
1 parent cd3ed4d commit 42738f0

18 files changed

+29
-74
lines changed

crates/oxc_linter/src/rules/eslint/no_array_constructor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ impl Rule for NoArrayConstructor {
6868
&new_expr.type_arguments,
6969
false,
7070
),
71-
_ => {
72-
return;
73-
}
71+
_ => return,
7472
};
7573

7674
let Expression::Identifier(ident) = &callee else {

crates/oxc_linter/src/rules/eslint/no_cond_assign.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ impl Rule for NoCondAssign {
111111
AstKind::Function(_)
112112
| AstKind::ArrowFunctionExpression(_)
113113
| AstKind::Program(_)
114-
| AstKind::BlockStatement(_) => {
115-
break;
116-
}
114+
| AstKind::BlockStatement(_) => break,
117115
_ => {}
118116
}
119117
}

crates/oxc_linter/src/rules/eslint/no_negated_condition.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ impl Rule for NoNegatedCondition {
7474
AstKind::ConditionalExpression(conditional_expr) => {
7575
conditional_expr.test.without_parentheses()
7676
}
77-
_ => {
78-
return;
79-
}
77+
_ => return,
8078
};
8179

8280
match stmt_test {
@@ -93,9 +91,7 @@ impl Rule for NoNegatedCondition {
9391
return;
9492
}
9593
}
96-
_ => {
97-
return;
98-
}
94+
_ => return,
9995
}
10096

10197
ctx.diagnostic(no_negated_condition_diagnostic(stmt_test.span()));

crates/oxc_linter/src/rules/eslint/no_object_constructor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ impl Rule for NoObjectConstructor {
5353
AstKind::NewExpression(new_expr) => {
5454
(new_expr.span, &new_expr.callee, &new_expr.arguments, &new_expr.type_arguments)
5555
}
56-
_ => {
57-
return;
58-
}
56+
_ => return,
5957
};
6058

6159
let Expression::Identifier(ident) = &callee else {

crates/oxc_linter/src/rules/eslint/no_self_assign.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@ impl NoSelfAssign {
312312
binding @ match_assignment_target!(AssignmentTargetMaybeDefault) => {
313313
binding.to_assignment_target()
314314
}
315-
AssignmentTargetMaybeDefault::AssignmentTargetWithDefault(_) => {
316-
return;
317-
}
315+
AssignmentTargetMaybeDefault::AssignmentTargetWithDefault(_) => return,
318316
};
319317
let ObjectPropertyKind::ObjectProperty(obj_prop) = right else {
320318
return;

crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,19 +497,15 @@ impl<'a> Symbol<'_, 'a> {
497497
// loops?
498498
AstKind::ForInStatement(_)
499499
| AstKind::ForOfStatement(_)
500-
| AstKind::WhileStatement(_) => {
501-
break;
502-
}
500+
| AstKind::WhileStatement(_) => break,
503501
// this is needed to handle `return () => foo++`
504502
AstKind::ExpressionStatement(_) => {
505503
if self.is_in_return_statement(node.id()) {
506504
return false;
507505
}
508506
break;
509507
}
510-
AstKind::Function(f) if f.is_declaration() => {
511-
break;
512-
}
508+
AstKind::Function(f) if f.is_declaration() => break,
513509
// implicit return in an arrow function
514510
AstKind::ArrowFunctionExpression(f)
515511
if f.body.statements.len() == 1

crates/oxc_linter/src/rules/import/namespace.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,10 @@ impl Rule for Namespace {
130130
let (source, module) = match &entry.import_name {
131131
ImportImportName::NamespaceObject => {
132132
let source = entry.module_request.name();
133-
match loaded_modules.get(source) {
134-
Some(module) => (source.to_string(), Arc::clone(module)),
135-
_ => {
136-
return;
137-
}
138-
}
133+
let Some(module) = loaded_modules.get(source) else {
134+
return;
135+
};
136+
(source.to_string(), Arc::clone(module))
139137
}
140138
ImportImportName::Name(name) => {
141139
let Some(loaded_module) = loaded_modules.get(entry.module_request.name())

crates/oxc_linter/src/rules/jest/no_standalone_expect/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,11 @@ fn is_correct_place_to_call_expect<'a>(
137137

138138
// loop until find the closest function body
139139
loop {
140-
match parent.kind() {
141-
AstKind::FunctionBody(_) => {
142-
break;
143-
}
144-
_ => {
145-
parent = ctx.nodes().parent_node(parent.id())?;
146-
}
140+
if matches!(parent.kind(), AstKind::FunctionBody(_)) {
141+
break;
147142
}
143+
144+
parent = ctx.nodes().parent_node(parent.id())?;
148145
}
149146

150147
let node = parent;

crates/oxc_linter/src/rules/jest/prefer_each.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ impl PreferEach {
100100

101101
for parent_node in ctx.nodes().ancestors(node.id()).skip(1) {
102102
match parent_node.kind() {
103-
AstKind::CallExpression(_) => {
104-
return;
105-
}
103+
AstKind::CallExpression(_) => return,
106104
AstKind::ForStatement(_)
107105
| AstKind::ForInStatement(_)
108106
| AstKind::ForOfStatement(_) => {

crates/oxc_linter/src/rules/jsx_a11y/iframe_has_title.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ impl Rule for IframeHasTitle {
9898
return;
9999
}
100100
}
101-
JSXExpression::CallExpression(_) => {
102-
return;
103-
}
101+
JSXExpression::CallExpression(_) => return,
104102
expr @ JSXExpression::Identifier(_) => {
105103
if !expr.is_undefined() {
106104
return;

0 commit comments

Comments
 (0)