fix(top-level-function): support async function
This commit is contained in:
parent
3fa861730d
commit
3a74c8e351
@ -36,6 +36,10 @@ const invalids = [
|
|||||||
'export const foo = () => ({})',
|
'export const foo = () => ({})',
|
||||||
'export function foo () { return {} }',
|
'export function foo () { return {} }',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'export const foo = async () => ({})',
|
||||||
|
'export async function foo () { return {} }',
|
||||||
|
],
|
||||||
]
|
]
|
||||||
|
|
||||||
it('runs', () => {
|
it('runs', () => {
|
||||||
|
@ -67,12 +67,14 @@ export default createEslintRule<Options, MessageIds>({
|
|||||||
const textTypeReturn = arrowFn.returnType
|
const textTypeReturn = arrowFn.returnType
|
||||||
? code.slice(arrowFn.returnType.range[0], arrowFn.returnType.range[1])
|
? 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({
|
// console.log({
|
||||||
// input: code.slice(node.range[0], node.range[1]),
|
// 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)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user