Skip to content

Commit

Permalink
fix: handle missing case for function overloads (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-merry authored Feb 27, 2024
1 parent 6a38d03 commit d36766c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/prefer-arrow-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ const alwaysValid = [
{
code: 'export function foo(val: string): void; export function foo(val: number): void; export function foo(val: string | number): void {}',
},
// export { x }; has node.declaration === null - regression test for this case
{
code: 'export { foo }; export function bar(val: number): void; export function bar(val: string | number): void {}',
},
];

const validWhenSingleReturnOnly = [
Expand Down Expand Up @@ -439,6 +443,13 @@ const invalidAndHasSingleReturn = [
output:
'var withLoop = async () => async () => { for (i = 0; i < 5; i++) {}}',
},

// function overloading - don't mislabel as overload
// export { x }; has node.declaration === null - regression test for this case
{
code: 'export { foo }; export async function bar() { return false; }',
output: 'export { foo }; export const bar = async () => false;',
},
];

const invalidAndHasSingleReturnWithMultipleMatches = [
Expand Down
4 changes: 2 additions & 2 deletions src/prefer-arrow-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
export default {
meta: {
docs: {
category: 'emcascript6',
category: 'ecmascript6',
description: 'prefer arrow functions',
recommended: false,
},
Expand Down Expand Up @@ -110,7 +110,7 @@ export default {
if (previousNode.type === 'TSDeclareFunction') return true;
if (
previousNode.type === 'ExportNamedDeclaration' &&
previousNode.declaration.type === 'TSDeclareFunction'
previousNode.declaration?.type === 'TSDeclareFunction'
)
return true;

Expand Down

0 comments on commit d36766c

Please sign in to comment.