@@ -144,7 +144,7 @@ export default createRule('consistent-selector-style', {
144144 if ( styleValue === 'class' ) {
145145 return ;
146146 }
147- if ( styleValue === 'id' && canUseIdSelector ( selection ) ) {
147+ if ( styleValue === 'id' && canUseIdSelector ( selection . map ( ( [ elem ] ) => elem ) ) ) {
148148 context . report ( {
149149 messageId : 'classShouldBeId' ,
150150 loc : styleSelectorNodeLoc ( node ) as AST . SourceLocation
@@ -286,11 +286,13 @@ function addToArrayMap<T>(
286286/**
287287 * Finds all nodes in selections that could be matched by key
288288 */
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+ ) ;
291293 selections . affixes . forEach ( ( nodes , [ prefix , suffix ] ) => {
292294 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 ] ) ) ;
294296 }
295297 } ) ;
296298 return selection ;
@@ -311,19 +313,32 @@ function canUseIdSelector(selection: AST.SvelteHTMLElement[]): boolean {
311313 * Checks whether a given selection could be obtained using a type selector
312314 */
313315function canUseTypeSelector (
314- selection : AST . SvelteHTMLElement [ ] ,
316+ selection : [ AST . SvelteHTMLElement , boolean ] [ ] ,
315317 typeSelections : Map < string , AST . SvelteHTMLElement [ ] >
316318) : boolean {
317- const types = new Set ( selection . map ( ( node ) => node . name . name ) ) ;
319+ const types = new Set ( selection . map ( ( [ node ] ) => node . name . name ) ) ;
318320 if ( types . size > 1 ) {
319321 return false ;
320322 }
321323 if ( types . size < 1 ) {
322324 return true ;
323325 }
326+ if (
327+ selection . some (
328+ ( [ elem , exact ] ) => ! exact && elementOccurrenceCount ( elem ) === ElementOccurenceCount . ZeroToInf
329+ )
330+ ) {
331+ return false ;
332+ }
324333 const type = [ ...types ] [ 0 ] ;
325334 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+ ) ;
327342}
328343
329344/**
0 commit comments