Skip to content

Commit a4bc977

Browse files
committed
fix(consistent-selector-style): Fixed counting of elements in Svelte blocks for ID selectors
1 parent f86813e commit a4bc977

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/eslint-plugin-svelte/src/rules/consistent-selector-style.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
extractExpressionSuffixLiteral
1313
} from '../utils/expression-affixes.js';
1414
import { createRule } from '../utils/index.js';
15+
import { ElementOccurenceCount, elementOccurrenceCount } from '../utils/element-occurences.js';
1516

1617
interface Selections {
1718
exact: Map<string, AST.SvelteHTMLElement[]>;
@@ -299,7 +300,11 @@ function matchSelection(selections: Selections, key: string): AST.SvelteHTMLElem
299300
* Checks whether a given selection could be obtained using an ID selector
300301
*/
301302
function canUseIdSelector(selection: AST.SvelteHTMLElement[]): boolean {
302-
return selection.length <= 1;
303+
return (
304+
selection.length === 0 ||
305+
(selection.length === 1 &&
306+
elementOccurrenceCount(selection[0]) !== ElementOccurenceCount.ZeroToInf)
307+
);
303308
}
304309

305310
/**

0 commit comments

Comments
 (0)