Skip to content

Commit d80c07c

Browse files
committed
fix(linter/explicit-module-boundary-types): false positve with arrow fn in exported fn body (#13232)
fixes #13209
1 parent c6c5075 commit d80c07c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

crates/oxc_linter/src/rules/typescript/explicit_module_boundary_types.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,23 @@ impl<'a> Visit<'a> for ExplicitTypesChecker<'a, '_> {
513513
}
514514
}
515515

516+
fn visit_statements(&mut self, it: &oxc_allocator::Vec<'a, Statement<'a>>) {
517+
for stmt in it {
518+
match stmt {
519+
Statement::ReturnStatement(_) => {
520+
self.visit_statement(stmt);
521+
}
522+
// Only process expression statements when they are the sole statement in the block.
523+
// This is typically to handle cases like concise arrow functions or modules with a single expression.
524+
// If this logic needs to be expanded to handle more cases, revisit this condition.
525+
Statement::ExpressionStatement(_) if it.len() == 1 => {
526+
self.visit_statement(stmt);
527+
}
528+
_ => {}
529+
}
530+
}
531+
}
532+
516533
fn visit_variable_declarator(&mut self, var: &VariableDeclarator<'a>) {
517534
if self.rule.allow_typed_function_expressions && var.id.type_annotation.is_some() {
518535
return;
@@ -1486,6 +1503,11 @@ mod test {
14861503
None,
14871504
),
14881505
("export namespace B{return}", None),
1506+
("function Test(): void { const _x = () => {}; } export default Test;", None),
1507+
(
1508+
"function Test(): void { const _x = () => { }; } function Test2() { return (): void => { }; } export { Test2 };",
1509+
None,
1510+
),
14891511
];
14901512

14911513
let fail = vec![
@@ -1965,6 +1987,10 @@ mod test {
19651987
",
19661988
None,
19671989
),
1990+
(
1991+
"function Test(): void { const _x = () => { }; } function Test2() { return () => { }; } export { Test2 };",
1992+
None,
1993+
),
19681994
];
19691995

19701996
Tester::new(

crates/oxc_linter/src/snapshots/typescript_explicit_module_boundary_types.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,9 @@ source: crates/oxc_linter/src/tester.rs
680680
· ────
681681
6return a;
682682
╰────
683+
684+
typescript-eslint(explicit-module-boundary-types): Missing return type on function
685+
╭─[explicit_module_boundary_types.tsx:1:75]
686+
1 │ function Test(): void { const _x = () => { }; } function Test2() { return () => { }; } export { Test2 };
687+
· ──
688+
╰────

0 commit comments

Comments
 (0)