@@ -13,6 +13,9 @@ module.exports = {
1313 consistentEventName :
1414 "Use an event name that can be derived from the function name" ,
1515 replaceEventName : `Replace value with {{value}}` ,
16+ missingEventStart :
17+ "Function accepts 'event' as the first argument, but doesn't call 'eventStart'." ,
18+ addEventStart : `Add 'eventStart(event, "")' in your function body.` ,
1619 } ,
1720 } ,
1821
@@ -23,12 +26,36 @@ module.exports = {
2326 currentFunction = {
2427 parent : currentFunction ,
2528 node,
26- isAsyncEventFunction : node . async && node . params [ 0 ] ?. name === "event" ,
29+ isAsyncEventFunction :
30+ node . async && node . id ?. name && node . params [ 0 ] ?. name === "event" ,
31+ hasEventStart : false ,
2732 functionName : node . id ?. name ,
2833 } ;
2934 }
3035
3136 function processFunctionEnd ( ) {
37+ if (
38+ currentFunction ?. isAsyncEventFunction &&
39+ ! currentFunction . hasEventStart
40+ ) {
41+ context . report ( {
42+ node : currentFunction . node . body ,
43+ messageId : "missingEventStart" ,
44+ suggest : [
45+ {
46+ messageId : "addEventStart" ,
47+ data : { } ,
48+ fix : function ( fixer ) {
49+ return fixer . insertTextBefore (
50+ currentFunction . node . body . body [ 0 ] ,
51+ `eventStart(event, "");\n ` ,
52+ ) ;
53+ } ,
54+ } ,
55+ ] ,
56+ } ) ;
57+ }
58+
3259 currentFunction = currentFunction . parent ;
3360 }
3461
@@ -39,18 +66,16 @@ module.exports = {
3966
4067 // Process `eventStart` calls
4168 "CallExpression[callee.name='eventStart']" ( node ) {
42- if (
43- ! currentFunction . isAsyncEventFunction ||
44- ! currentFunction . functionName ||
45- currentFunction . functionName . length === 0
46- ) {
69+ if ( ! currentFunction ?. isAsyncEventFunction ) {
4770 return ;
4871 }
4972
5073 if ( node . arguments ?. length !== 2 ) {
5174 return ;
5275 }
5376
77+ currentFunction . hasEventStart = true ;
78+
5479 let value = undefined ;
5580 if ( node . arguments [ 1 ] . type === "Literal" ) {
5681 value = node . arguments [ 1 ] . value ;
0 commit comments