Skip to content

Commit fd14b39

Browse files
committed
fix(linter/array-callback-return): false postive with throw stmt in callback (#13264)
fixes #13256
1 parent 648e939 commit fd14b39

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ fn test() {
426426
("foo[`${every}`](function() {})", None),
427427
("foo.every(() => true)", None),
428428
("return function() {}", None),
429+
(
430+
"array.map((node) => { if (isTaskNode(node)) { return someObj; } else if (isOtherNode(node)) { return otherObj; } else { throw new Error('Unsupported'); } })",
431+
None,
432+
),
429433
];
430434

431435
let fail = vec![

crates/oxc_linter/src/rules/eslint/array_callback_return/return_checker.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ pub fn check_statement(statement: &Statement) -> StatementReturnStatus {
200200
status
201201
}
202202

203+
Statement::ThrowStatement(_) => StatementReturnStatus::AlwaysExplicit,
204+
203205
_ => StatementReturnStatus::NotReturn,
204206
}
205207
}
@@ -448,4 +450,30 @@ mod tests {
448450
";
449451
parse_statement_and_test(source, StatementReturnStatus::AlwaysImplicit);
450452
}
453+
454+
#[test]
455+
fn test_throw_statement() {
456+
let source = "
457+
function foo() {
458+
throw new Error('test');
459+
}
460+
";
461+
parse_statement_and_test(source, StatementReturnStatus::AlwaysExplicit);
462+
}
463+
464+
#[test]
465+
fn test_if_with_throw() {
466+
let source = "
467+
function foo() {
468+
if (a) {
469+
return 1;
470+
} else if (b) {
471+
return 2;
472+
} else {
473+
throw new Error('test');
474+
}
475+
}
476+
";
477+
parse_statement_and_test(source, StatementReturnStatus::AlwaysExplicit);
478+
}
451479
}

0 commit comments

Comments
 (0)