@@ -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,7 @@ 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 ExportDefaultDeclaration (ESM)
251247module . exports = {
252248 rules : {
253249 "required-properties-key" : {
@@ -256,7 +252,7 @@ module.exports = {
256252 ExpressionStatement ( node ) {
257253 componentContainsPropertyCheck ( context , node , "key" ) ;
258254 } ,
259- Program ( node ) {
255+ ExportDefaultDeclaration ( node ) {
260256 componentContainsPropertyCheck ( context , node , "key" ) ;
261257 } ,
262258 } ;
@@ -268,7 +264,7 @@ module.exports = {
268264 ExpressionStatement ( node ) {
269265 componentContainsPropertyCheck ( context , node , "name" ) ;
270266 } ,
271- Program ( node ) {
267+ ExportDefaultDeclaration ( node ) {
272268 componentContainsPropertyCheck ( context , node , "name" ) ;
273269 } ,
274270 } ;
@@ -280,7 +276,7 @@ module.exports = {
280276 ExpressionStatement ( node ) {
281277 componentContainsPropertyCheck ( context , node , "version" ) ;
282278 } ,
283- Program ( node ) {
279+ ExportDefaultDeclaration ( node ) {
284280 componentContainsPropertyCheck ( context , node , "version" ) ;
285281 } ,
286282 } ;
@@ -292,7 +288,7 @@ module.exports = {
292288 ExpressionStatement ( node ) {
293289 componentContainsPropertyCheck ( context , node , "description" ) ;
294290 } ,
295- Program ( node ) {
291+ ExportDefaultDeclaration ( node ) {
296292 componentContainsPropertyCheck ( context , node , "description" ) ;
297293 } ,
298294 } ;
@@ -304,7 +300,7 @@ module.exports = {
304300 ExpressionStatement ( node ) {
305301 componentContainsPropertyCheck ( context , node , "type" , "Components must export a type property (\"source\" or \"action\")" ) ;
306302 } ,
307- Program ( node ) {
303+ ExportDefaultDeclaration ( node ) {
308304 componentContainsPropertyCheck ( context , node , "type" , "Components must export a type property (\"source\" or \"action\")" ) ;
309305 } ,
310306 } ;
@@ -316,7 +312,7 @@ module.exports = {
316312 ExpressionStatement ( node ) {
317313 componentPropsContainsPropertyCheck ( context , node , "label" ) ;
318314 } ,
319- Program ( node ) {
315+ ExportDefaultDeclaration ( node ) {
320316 componentPropsContainsPropertyCheck ( context , node , "label" ) ;
321317 } ,
322318 } ;
@@ -328,7 +324,7 @@ module.exports = {
328324 ExpressionStatement ( node ) {
329325 componentPropsContainsPropertyCheck ( context , node , "description" ) ;
330326 } ,
331- Program ( node ) {
327+ ExportDefaultDeclaration ( node ) {
332328 componentPropsContainsPropertyCheck ( context , node , "description" ) ;
333329 } ,
334330 } ;
@@ -340,7 +336,7 @@ module.exports = {
340336 ExpressionStatement ( node ) {
341337 optionalComponentPropsHaveDefaultProperty ( context , node ) ;
342338 } ,
343- Program ( node ) {
339+ ExportDefaultDeclaration ( node ) {
344340 optionalComponentPropsHaveDefaultProperty ( context , node ) ;
345341 } ,
346342 } ;
@@ -352,7 +348,7 @@ module.exports = {
352348 ExpressionStatement ( node ) {
353349 componentSourceNameCheck ( context , node ) ;
354350 } ,
355- Program ( node ) {
351+ ExportDefaultDeclaration ( node ) {
356352 componentSourceNameCheck ( context , node ) ;
357353 } ,
358354 } ;
@@ -364,7 +360,7 @@ module.exports = {
364360 ExpressionStatement ( node ) {
365361 componentSourceDescriptionCheck ( context , node ) ;
366362 } ,
367- Program ( node ) {
363+ ExportDefaultDeclaration ( node ) {
368364 componentSourceDescriptionCheck ( context , node ) ;
369365 } ,
370366 } ;
@@ -376,7 +372,7 @@ module.exports = {
376372 ExpressionStatement ( node ) {
377373 componentVersionTsMacroCheck ( context , node ) ;
378374 } ,
379- Program ( node ) {
375+ ExportDefaultDeclaration ( node ) {
380376 componentVersionTsMacroCheck ( context , node ) ;
381377 } ,
382378 } ;
0 commit comments