@@ -19,31 +19,36 @@ export default {
19
19
{
20
20
type : 'object' ,
21
21
properties : {
22
- packageName : {
23
- type : 'string' ,
22
+ packageNames : {
23
+ type : 'array' ,
24
+ items : { type : 'string' } ,
25
+ minItems : 1 ,
24
26
} ,
25
27
} ,
26
- additionalProperties : false ,
28
+ // additionalProperties: false,
27
29
} ,
28
30
] ,
29
31
} ,
30
32
create ( context ) {
31
- const packageName = context . options [ 0 ] && context . options [ 0 ] . packageName ;
32
- if ( ! packageName ) {
33
+ const packageNames = context . options [ 0 ] ?. packageNames || [ ] ;
34
+ if ( packageNames . length === 0 ) {
33
35
return { } ;
34
36
}
35
37
36
- const importedComponents = new Set ( ) ;
38
+ const importedComponents = new Map < string , Set < string > > ( ) ; // Map to store components per package name
37
39
38
40
return {
39
41
ImportDeclaration ( node ) {
40
- if ( node . source . value === packageName ) {
42
+ if ( packageNames . includes ( node . source . value ) ) {
41
43
node . specifiers . forEach ( specifier => {
42
44
if (
43
45
specifier . type === 'ImportSpecifier' ||
44
46
specifier . type === 'ImportDefaultSpecifier'
45
47
) {
46
- importedComponents . add ( specifier . local . name ) ;
48
+ if ( ! importedComponents . has ( node . source . value ) ) {
49
+ importedComponents . set ( node . source . value , new Set < string > ( ) ) ;
50
+ }
51
+ importedComponents . get ( node . source . value ) . add ( specifier . local . name ) ;
47
52
}
48
53
} ) ;
49
54
}
@@ -52,16 +57,23 @@ export default {
52
57
if (
53
58
node . tag . type === 'CallExpression' &&
54
59
node . tag . callee . name === 'styled' &&
55
- node . tag . arguments [ 0 ] . type === 'Identifier' &&
56
- importedComponents . has ( node . tag . arguments [ 0 ] . name )
60
+ node . tag . arguments [ 0 ] . type === 'Identifier'
57
61
) {
58
- context . report ( {
59
- node,
60
- messageId : 'avoidStyledComponent' ,
61
- data : {
62
- packageName,
63
- } ,
64
- } ) ;
62
+ const componentName = node . tag . arguments [ 0 ] . name ;
63
+
64
+ // Check if component name matches any imported component from the specified packages
65
+ for ( const [ pkgName , components ] of importedComponents ) {
66
+ if ( components . has ( componentName ) ) {
67
+ context . report ( {
68
+ node,
69
+ messageId : 'avoidStyledComponent' ,
70
+ data : {
71
+ packageName : pkgName ,
72
+ } ,
73
+ } ) ;
74
+ break ;
75
+ }
76
+ }
65
77
}
66
78
} ,
67
79
} ;
0 commit comments