Skip to content

Commit e38115e

Browse files
wagenetclaudecamc314
authored
fix(linter): catch missing return type on exported arrow/function expressions (#19587)
## Summary - `run_on_exported_expression_inner` called `walk::walk_arrow_function_expression` (the raw walk function) instead of `checker.visit_arrow_function_expression`. The raw walk visits AST children but bypasses `ExplicitTypesChecker::visit_arrow_function_expression`, which is the method that calls `check_arrow_without_return`. Block-body arrow functions with no inner function expressions produced no diagnostic. - Added symmetric fix for `FunctionExpression`: `export default (function() { ... })` was silently ignored by the `_` arm. ### Incorrect behavior before fix ```ts // Not flagged by oxlint, but should be export default ({ connectorTypeEnumCase, connectorFriendlyName, }: { connectorTypeEnumCase: string; connectorFriendlyName: string; }) => { return `${connectorTypeEnumCase}`; }; ``` ### Snapshot correction `export default () => (true ? () => {} : (): void => {})` now points to the outer exported arrow (the module boundary) instead of the inner `() => {}`. ## Test plan - [ ] Existing `explicit_module_boundary_types` tests all pass - [ ] New fail test: destructured-param arrow with block body - [ ] New fail test: `export default (function() { ... })` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Cameron <cameron.clark@hey.com>
1 parent 419d3fd commit e38115e

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ impl ExplicitModuleBoundaryTypes {
232232
Self::run_on_identifier_reference(ctx, id, &mut checker);
233233
}
234234
Expression::ArrowFunctionExpression(arrow) => {
235-
walk::walk_arrow_function_expression(&mut checker, arrow);
235+
checker.visit_arrow_function_expression(arrow);
236+
}
237+
Expression::FunctionExpression(func) => {
238+
checker.visit_function(func, ScopeFlags::Function);
236239
}
237240
// const foo = arg => arg;
238241
// export default [foo];
@@ -2000,6 +2003,23 @@ mod test {
20002003
None,
20012004
),
20022005
("function App() { return 42; } export default App", None),
2006+
(
2007+
"
2008+
export default ({
2009+
a,
2010+
b,
2011+
c,
2012+
}: {
2013+
a: string;
2014+
b: string;
2015+
c: string;
2016+
}) => {
2017+
return `${a} ${b} ${c}`;
2018+
};
2019+
",
2020+
None,
2021+
),
2022+
("export default (function() { return 'test'; });", None),
20032023
];
20042024

20052025
Tester::new(

crates/oxc_linter/src/snapshots/typescript_explicit_module_boundary_types.snap

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_linter/src/tester.rs
33
---
4-
54
typescript-eslint(explicit-module-boundary-types): Missing return type on function
65
╭─[explicit_module_boundary_types.tsx:1:17]
76
1 │ export function test(a: number, b: number) { return; }
@@ -115,9 +114,9 @@ source: crates/oxc_linter/src/tester.rs
115114
╰────
116115

117116
typescript-eslint(explicit-module-boundary-types): Missing return type on function
118-
╭─[explicit_module_boundary_types.tsx:1:30]
117+
╭─[explicit_module_boundary_types.tsx:1:16]
119118
1 │ export default () => (true ? () => {} : (): void => {});
120-
· ──
119+
· ──
121120
╰────
122121

123122
typescript-eslint(explicit-module-boundary-types): Missing return type on function
@@ -717,3 +716,24 @@ source: crates/oxc_linter/src/tester.rs
717716
1 │ function App() { return 42; } export default App
718717
· ───
719718
╰────
719+
720+
typescript-eslint(explicit-module-boundary-types): Missing return type on function
721+
╭─[explicit_module_boundary_types.tsx:2:28]
722+
1 │
723+
2 │ ╭─▶ export default ({
724+
3 │ │ a,
725+
4 │ │ b,
726+
5 │ │ c,
727+
6 │ │ }: {
728+
7 │ │ a: string;
729+
8 │ │ b: string;
730+
9 │ │ c: string;
731+
10 │ ╰─▶ }) => {
732+
11return `${a} ${b} ${c}`;
733+
╰────
734+
735+
typescript-eslint(explicit-module-boundary-types): Missing return type on function
736+
╭─[explicit_module_boundary_types.tsx:1:17]
737+
1 │ export default (function() { return 'test'; });
738+
· ────────
739+
╰────

0 commit comments

Comments
 (0)