File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,13 @@ function create(context) {
2727 node : node . init ,
2828 message : 'Top-level functions must be named/regular functions.' ,
2929 fix ( fixer ) {
30- const fixedCode = `function ${ functionName } ${ functionText . slice ( functionText . indexOf ( '(' ) ) } ` ;
30+ const isSingleExpression = node . init . body . type !== 'BlockStatement' ;
31+ const functionBody = isSingleExpression
32+ ? `{ return ${ functionText . slice ( functionText . indexOf ( '=>' ) + 3 ) } ; }`
33+ : functionText . slice ( functionText . indexOf ( '{' ) ) ;
34+ const functionParameters = functionText . slice ( 0 , functionText . indexOf ( '=>' ) ) . trim ( ) ;
35+
36+ const fixedCode = `function ${ functionName } ${ functionParameters } ${ functionBody } ` ;
3137 return fixer . replaceText ( node . parent , fixedCode ) ;
3238 } ,
3339 } ) ;
@@ -61,7 +67,6 @@ function create(context) {
6167 const functionName = 'defaultFunction' ;
6268 const sourceCode = context . getSourceCode ( ) ;
6369 const functionText = sourceCode . getText ( node ) ;
64-
6570 const fixedCode = functionText . replace ( 'function (' , `function ${ functionName } (` ) ;
6671
6772 return fixer . replaceText ( node , fixedCode ) ;
You can’t perform that action at this time.
0 commit comments