Skip to content

Commit

Permalink
fix: TypeError on function f() { return; }
Browse files Browse the repository at this point in the history
Fixes JamieMason#38.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information
andersk committed Jun 7, 2024
1 parent a34f8f9 commit fd2fadd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/prefer-arrow-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ const invalidAndHasBlockStatement = [
code: 'async function foo(a) { console.log(3); }',
output: 'const foo = async (a) => { console.log(3); };',
},
{
code: 'function foo() { return; }',
output: 'const foo = () => { return; };',
},

// https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions/issues/28
{
Expand Down
3 changes: 2 additions & 1 deletion src/prefer-arrow-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default {
return (
node.body.body &&
node.body.body.length === 1 &&
node.body.body[0].type === 'ReturnStatement'
node.body.body[0].type === 'ReturnStatement' &&
node.body.body[0].argument !== null
);
};

Expand Down

0 comments on commit fd2fadd

Please sign in to comment.