@@ -144,7 +144,7 @@ export default createRule('consistent-selector-style', {
144
144
if ( styleValue === 'class' ) {
145
145
return ;
146
146
}
147
- if ( styleValue === 'id' && canUseIdSelector ( selection ) ) {
147
+ if ( styleValue === 'id' && canUseIdSelector ( selection . map ( ( [ elem ] ) => elem ) ) ) {
148
148
context . report ( {
149
149
messageId : 'classShouldBeId' ,
150
150
loc : styleSelectorNodeLoc ( node ) as AST . SourceLocation
@@ -286,11 +286,13 @@ function addToArrayMap<T>(
286
286
/**
287
287
* Finds all nodes in selections that could be matched by key
288
288
*/
289
- function matchSelection ( selections : Selections , key : string ) : AST . SvelteHTMLElement [ ] {
290
- const selection = selections . exact . get ( key ) ?? [ ] ;
289
+ function matchSelection ( selections : Selections , key : string ) : [ AST . SvelteHTMLElement , boolean ] [ ] {
290
+ const selection = ( selections . exact . get ( key ) ?? [ ] ) . map < [ AST . SvelteHTMLElement , boolean ] > (
291
+ ( elem ) => [ elem , true ]
292
+ ) ;
291
293
selections . affixes . forEach ( ( nodes , [ prefix , suffix ] ) => {
292
294
if ( ( prefix === null || key . startsWith ( prefix ) ) && ( suffix === null || key . endsWith ( suffix ) ) ) {
293
- selection . push ( ...nodes ) ;
295
+ selection . push ( ...nodes . map < [ AST . SvelteHTMLElement , boolean ] > ( ( elem ) => [ elem , false ] ) ) ;
294
296
}
295
297
} ) ;
296
298
return selection ;
@@ -311,19 +313,32 @@ function canUseIdSelector(selection: AST.SvelteHTMLElement[]): boolean {
311
313
* Checks whether a given selection could be obtained using a type selector
312
314
*/
313
315
function canUseTypeSelector (
314
- selection : AST . SvelteHTMLElement [ ] ,
316
+ selection : [ AST . SvelteHTMLElement , boolean ] [ ] ,
315
317
typeSelections : Map < string , AST . SvelteHTMLElement [ ] >
316
318
) : boolean {
317
- const types = new Set ( selection . map ( ( node ) => node . name . name ) ) ;
319
+ const types = new Set ( selection . map ( ( [ node ] ) => node . name . name ) ) ;
318
320
if ( types . size > 1 ) {
319
321
return false ;
320
322
}
321
323
if ( types . size < 1 ) {
322
324
return true ;
323
325
}
326
+ if (
327
+ selection . some (
328
+ ( [ elem , exact ] ) => ! exact && elementOccurrenceCount ( elem ) === ElementOccurenceCount . ZeroToInf
329
+ )
330
+ ) {
331
+ return false ;
332
+ }
324
333
const type = [ ...types ] [ 0 ] ;
325
334
const typeSelection = typeSelections . get ( type ) ;
326
- return typeSelection !== undefined && arrayEquals ( typeSelection , selection ) ;
335
+ return (
336
+ typeSelection !== undefined &&
337
+ arrayEquals (
338
+ typeSelection ,
339
+ selection . map ( ( [ elem ] ) => elem )
340
+ )
341
+ ) ;
327
342
}
328
343
329
344
/**
0 commit comments