@@ -6,10 +6,7 @@ function isModuleExports(node) {
66}
77
88function isDefaultExport ( node ) {
9- if ( ! node ) return false ;
10- if ( node . type !== "Program" || ! node . body || ! node . body . length ) return false ;
11- if ( node ?. body [ 0 ] ?. type !== "ExportDefaultDeclaration" ) return false ;
12- return true ;
9+ return node ?. type === "ExportDefaultDeclaration" ;
1310}
1411
1512function isObjectWithProperties ( node ) {
@@ -49,7 +46,7 @@ function findPropertyWithName(name, propertyArray) {
4946function componentContainsPropertyCheck ( context , node , propertyName , message ) {
5047 let component ;
5148 if ( isDefaultExport ( node ) ) {
52- component = node ?. body [ 0 ] ? .declaration ;
49+ component = node . declaration ;
5350 }
5451
5552 if ( node . expression ) {
@@ -85,9 +82,8 @@ function getProps(moduleProperties) {
8582function componentPropsContainsPropertyCheck ( context , node , propertyName ) {
8683 let component ;
8784 if ( isDefaultExport ( node ) ) {
88- component = node ?. body [ 0 ] ? .declaration ;
85+ component = node . declaration ;
8986 }
90-
9187 if ( node . expression ) {
9288 const {
9389 left,
@@ -125,7 +121,7 @@ function componentPropsContainsPropertyCheck(context, node, propertyName) {
125121function optionalComponentPropsHaveDefaultProperty ( context , node ) {
126122 let component ;
127123 if ( isDefaultExport ( node ) ) {
128- component = node ?. body [ 0 ] ? .declaration ;
124+ component = node . declaration ;
129125 }
130126
131127 if ( node . expression ) {
@@ -172,7 +168,7 @@ function optionalComponentPropsHaveDefaultProperty(context, node) {
172168function checkComponentIsSourceAndReturnTargetProp ( node , propertyName ) {
173169 let component ;
174170 if ( isDefaultExport ( node ) ) {
175- component = node ?. body [ 0 ] ? .declaration ;
171+ component = node . declaration ;
176172 }
177173
178174 if ( node . expression ) {
@@ -221,7 +217,7 @@ function componentSourceDescriptionCheck(context, node) {
221217function componentVersionTsMacroCheck ( context , node ) {
222218 let component ;
223219 if ( isDefaultExport ( node ) ) {
224- component = node ?. body [ 0 ] ? .declaration ;
220+ component = node . declaration ;
225221 }
226222
227223 if ( node . expression ) {
@@ -247,7 +243,8 @@ function componentVersionTsMacroCheck(context, node) {
247243 }
248244}
249245
250- // Rules run on two different AST node types: ExpressionStatement (CJS) and Program (ESM)
246+ // Rules run on two different AST node types: ExpressionStatement (CJS) and
247+ // ExportDefaultDeclaration (ESM)
251248module . exports = {
252249 rules : {
253250 "required-properties-key" : {
@@ -256,7 +253,7 @@ module.exports = {
256253 ExpressionStatement ( node ) {
257254 componentContainsPropertyCheck ( context , node , "key" ) ;
258255 } ,
259- Program ( node ) {
256+ ExportDefaultDeclaration ( node ) {
260257 componentContainsPropertyCheck ( context , node , "key" ) ;
261258 } ,
262259 } ;
@@ -268,7 +265,7 @@ module.exports = {
268265 ExpressionStatement ( node ) {
269266 componentContainsPropertyCheck ( context , node , "name" ) ;
270267 } ,
271- Program ( node ) {
268+ ExportDefaultDeclaration ( node ) {
272269 componentContainsPropertyCheck ( context , node , "name" ) ;
273270 } ,
274271 } ;
@@ -280,7 +277,7 @@ module.exports = {
280277 ExpressionStatement ( node ) {
281278 componentContainsPropertyCheck ( context , node , "version" ) ;
282279 } ,
283- Program ( node ) {
280+ ExportDefaultDeclaration ( node ) {
284281 componentContainsPropertyCheck ( context , node , "version" ) ;
285282 } ,
286283 } ;
@@ -292,7 +289,7 @@ module.exports = {
292289 ExpressionStatement ( node ) {
293290 componentContainsPropertyCheck ( context , node , "description" ) ;
294291 } ,
295- Program ( node ) {
292+ ExportDefaultDeclaration ( node ) {
296293 componentContainsPropertyCheck ( context , node , "description" ) ;
297294 } ,
298295 } ;
@@ -304,7 +301,7 @@ module.exports = {
304301 ExpressionStatement ( node ) {
305302 componentContainsPropertyCheck ( context , node , "type" , "Components must export a type property (\"source\" or \"action\")" ) ;
306303 } ,
307- Program ( node ) {
304+ ExportDefaultDeclaration ( node ) {
308305 componentContainsPropertyCheck ( context , node , "type" , "Components must export a type property (\"source\" or \"action\")" ) ;
309306 } ,
310307 } ;
@@ -316,7 +313,7 @@ module.exports = {
316313 ExpressionStatement ( node ) {
317314 componentPropsContainsPropertyCheck ( context , node , "label" ) ;
318315 } ,
319- Program ( node ) {
316+ ExportDefaultDeclaration ( node ) {
320317 componentPropsContainsPropertyCheck ( context , node , "label" ) ;
321318 } ,
322319 } ;
@@ -328,7 +325,7 @@ module.exports = {
328325 ExpressionStatement ( node ) {
329326 componentPropsContainsPropertyCheck ( context , node , "description" ) ;
330327 } ,
331- Program ( node ) {
328+ ExportDefaultDeclaration ( node ) {
332329 componentPropsContainsPropertyCheck ( context , node , "description" ) ;
333330 } ,
334331 } ;
@@ -340,7 +337,7 @@ module.exports = {
340337 ExpressionStatement ( node ) {
341338 optionalComponentPropsHaveDefaultProperty ( context , node ) ;
342339 } ,
343- Program ( node ) {
340+ ExportDefaultDeclaration ( node ) {
344341 optionalComponentPropsHaveDefaultProperty ( context , node ) ;
345342 } ,
346343 } ;
@@ -352,7 +349,7 @@ module.exports = {
352349 ExpressionStatement ( node ) {
353350 componentSourceNameCheck ( context , node ) ;
354351 } ,
355- Program ( node ) {
352+ ExportDefaultDeclaration ( node ) {
356353 componentSourceNameCheck ( context , node ) ;
357354 } ,
358355 } ;
@@ -364,7 +361,7 @@ module.exports = {
364361 ExpressionStatement ( node ) {
365362 componentSourceDescriptionCheck ( context , node ) ;
366363 } ,
367- Program ( node ) {
364+ ExportDefaultDeclaration ( node ) {
368365 componentSourceDescriptionCheck ( context , node ) ;
369366 } ,
370367 } ;
@@ -376,7 +373,7 @@ module.exports = {
376373 ExpressionStatement ( node ) {
377374 componentVersionTsMacroCheck ( context , node ) ;
378375 } ,
379- Program ( node ) {
376+ ExportDefaultDeclaration ( node ) {
380377 componentVersionTsMacroCheck ( context , node ) ;
381378 } ,
382379 } ;
0 commit comments