@@ -33,8 +33,12 @@ export default createEslintRule<Options, MessageIds>({
3333
3434 const declaration = node . declarations [ 0 ]
3535
36- if ( declaration . init ?. type !== 'ArrowFunctionExpression' )
36+ if (
37+ declaration . init ?. type !== 'ArrowFunctionExpression'
38+ && declaration . init ?. type !== 'FunctionExpression'
39+ ) {
3740 return
41+ }
3842 if ( declaration . id ?. type !== 'Identifier' )
3943 return
4044 if ( declaration . id . typeAnnotation )
@@ -46,7 +50,7 @@ export default createEslintRule<Options, MessageIds>({
4650 return
4751 }
4852
49- const arrowFn = declaration . init
53+ const fnExpression = declaration . init
5054 const body = declaration . init . body
5155 const id = declaration . id
5256
@@ -60,19 +64,19 @@ export default createEslintRule<Options, MessageIds>({
6064 fix ( fixer ) {
6165 const code = context . getSourceCode ( ) . text
6266 const textName = code . slice ( id . range [ 0 ] , id . range [ 1 ] )
63- const textArgs = arrowFn . params . length
64- ? code . slice ( arrowFn . params [ 0 ] . range [ 0 ] , arrowFn . params [ arrowFn . params . length - 1 ] . range [ 1 ] )
67+ const textArgs = fnExpression . params . length
68+ ? code . slice ( fnExpression . params [ 0 ] . range [ 0 ] , fnExpression . params [ fnExpression . params . length - 1 ] . range [ 1 ] )
6569 : ''
6670 const textBody = body . type === 'BlockStatement'
6771 ? code . slice ( body . range [ 0 ] , body . range [ 1 ] )
6872 : `{\n return ${ code . slice ( body . range [ 0 ] , body . range [ 1 ] ) } \n}`
69- const textGeneric = arrowFn . typeParameters
70- ? code . slice ( arrowFn . typeParameters . range [ 0 ] , arrowFn . typeParameters . range [ 1 ] )
73+ const textGeneric = fnExpression . typeParameters
74+ ? code . slice ( fnExpression . typeParameters . range [ 0 ] , fnExpression . typeParameters . range [ 1 ] )
7175 : ''
72- const textTypeReturn = arrowFn . returnType
73- ? code . slice ( arrowFn . returnType . range [ 0 ] , arrowFn . returnType . range [ 1 ] )
76+ const textTypeReturn = fnExpression . returnType
77+ ? code . slice ( fnExpression . returnType . range [ 0 ] , fnExpression . returnType . range [ 1 ] )
7478 : ''
75- const textAsync = arrowFn . async ? 'async ' : ''
79+ const textAsync = fnExpression . async ? 'async ' : ''
7680
7781 const final = `${ textAsync } function ${ textName } ${ textGeneric } (${ textArgs } )${ textTypeReturn } ${ textBody } `
7882 // console.log({
0 commit comments