diff --git a/packages/eslint-plugin-antfu/src/rules/top-level-function.test.ts b/packages/eslint-plugin-antfu/src/rules/top-level-function.test.ts index c4b917a..e975e45 100644 --- a/packages/eslint-plugin-antfu/src/rules/top-level-function.test.ts +++ b/packages/eslint-plugin-antfu/src/rules/top-level-function.test.ts @@ -36,6 +36,10 @@ const invalids = [ 'export const foo = () => ({})', 'export function foo () { return {} }', ], + [ + 'export const foo = async () => ({})', + 'export async function foo () { return {} }', + ], ] it('runs', () => { diff --git a/packages/eslint-plugin-antfu/src/rules/top-level-function.ts b/packages/eslint-plugin-antfu/src/rules/top-level-function.ts index 9a5056e..0986f4a 100644 --- a/packages/eslint-plugin-antfu/src/rules/top-level-function.ts +++ b/packages/eslint-plugin-antfu/src/rules/top-level-function.ts @@ -67,12 +67,14 @@ export default createEslintRule({ const textTypeReturn = arrowFn.returnType ? code.slice(arrowFn.returnType.range[0], arrowFn.returnType.range[1]) : '' - const text = `function ${textName} ${textGeneric}(${textArgs})${textTypeReturn} ${textBody}` + const textAsync = arrowFn.async ? 'async ' : '' + + const final = `${textAsync}function ${textName} ${textGeneric}(${textArgs})${textTypeReturn} ${textBody}` // console.log({ // input: code.slice(node.range[0], node.range[1]), - // output: text, + // output: final, // }) - return fixer.replaceTextRange([node.range[0], node.range[1]], text) + return fixer.replaceTextRange([node.range[0], node.range[1]], final) }, }) },