diff --git a/crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs b/crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs index 442cb45f3ac18..030a8c223da29 100644 --- a/crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs +++ b/crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs @@ -426,6 +426,10 @@ fn test() { ("foo[`${every}`](function() {})", None), ("foo.every(() => true)", None), ("return function() {}", None), + ( + "array.map((node) => { if (isTaskNode(node)) { return someObj; } else if (isOtherNode(node)) { return otherObj; } else { throw new Error('Unsupported'); } })", + None, + ), ]; let fail = vec![ diff --git a/crates/oxc_linter/src/rules/eslint/array_callback_return/return_checker.rs b/crates/oxc_linter/src/rules/eslint/array_callback_return/return_checker.rs index 89732826570da..b8b3a0a912df0 100644 --- a/crates/oxc_linter/src/rules/eslint/array_callback_return/return_checker.rs +++ b/crates/oxc_linter/src/rules/eslint/array_callback_return/return_checker.rs @@ -200,6 +200,8 @@ pub fn check_statement(statement: &Statement) -> StatementReturnStatus { status } + Statement::ThrowStatement(_) => StatementReturnStatus::AlwaysExplicit, + _ => StatementReturnStatus::NotReturn, } } @@ -448,4 +450,30 @@ mod tests { "; parse_statement_and_test(source, StatementReturnStatus::AlwaysImplicit); } + + #[test] + fn test_throw_statement() { + let source = " + function foo() { + throw new Error('test'); + } + "; + parse_statement_and_test(source, StatementReturnStatus::AlwaysExplicit); + } + + #[test] + fn test_if_with_throw() { + let source = " + function foo() { + if (a) { + return 1; + } else if (b) { + return 2; + } else { + throw new Error('test'); + } + } + "; + parse_statement_and_test(source, StatementReturnStatus::AlwaysExplicit); + } }