@@ -263,9 +263,11 @@ impl Rule for OnlyExportComponents {
263
263
}
264
264
265
265
fn run_once ( & self , ctx : & LintContext < ' _ > ) {
266
- let react_is_in_scope = ctx. semantic ( ) . nodes ( ) . iter ( ) . any ( |node| {
267
- matches ! ( node. kind( ) , AstKind :: ImportDeclaration ( import_decl) if import_decl. source. value == "react" )
268
- } ) ;
266
+ let react_is_in_scope = ctx
267
+ . module_record ( )
268
+ . import_entries
269
+ . iter ( )
270
+ . any ( |entry| entry. module_request . name == "react" ) ;
269
271
if self . check_js && !react_is_in_scope {
270
272
return ;
271
273
}
@@ -349,27 +351,32 @@ impl OnlyExportComponents {
349
351
350
352
fn analyze_exports ( & self , ctx : & LintContext , react_hocs : & [ & str ] ) -> ExportAnalysis {
351
353
let mut analysis = ExportAnalysis :: default ( ) ;
354
+ let module_record = ctx. module_record ( ) ;
355
+
356
+ let has_any_exports = !module_record. local_export_entries . is_empty ( )
357
+ || !module_record. star_export_entries . is_empty ( )
358
+ || !module_record. indirect_export_entries . is_empty ( ) ;
359
+ if !has_any_exports {
360
+ return analysis;
361
+ }
362
+
363
+ analysis. has_exports = true ;
352
364
353
365
for node in ctx. semantic ( ) . nodes ( ) {
354
366
match node. kind ( ) {
355
367
AstKind :: ExportAllDeclaration ( export_all) if export_all. export_kind . is_value ( ) => {
356
- analysis. has_exports = true ;
357
368
ctx. diagnostic ( export_all_components_diagnostic ( export_all. span ) ) ;
358
369
}
359
370
AstKind :: ExportDefaultDeclaration ( export_default) => {
360
- analysis. has_exports = true ;
361
371
let result = self . analyze_export_default ( export_default, react_hocs) ;
362
-
363
372
if let Some ( span) = result. anonymous_span {
364
373
ctx. diagnostic ( anonymous_components_diagnostic ( span) ) ;
365
374
}
366
-
367
375
analysis. merge ( result) ;
368
376
}
369
377
AstKind :: ExportNamedDeclaration ( export_named)
370
378
if export_named. export_kind . is_value ( ) =>
371
379
{
372
- analysis. has_exports = true ;
373
380
let result = self . analyze_export_named ( ctx, export_named, react_hocs) ;
374
381
analysis. merge ( result) ;
375
382
}
0 commit comments