-
-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Hi,
when coding consistent-selector-style
, I made a mistake (in fact, multiple, but I already opened another issues :D). The ID selector in Svelte is quite problematic, it turns out. While scoped styles ensure that any styles applied to ID-selected elements remains scoped, the ID itself is not rewritten, meaning that if a Svelte component contains a HTML element with an ID and is included in the page more than once, the page HTML is actually invalid (because having two elements with the same ID in the same HTML document is forbidden). While browsers generally don't care, I don't think eslint-plugin-svelte should promote this.
Here is where consistent-selector-style
comes in - it actually promotes ID selectors over class selectors in the default configuration. And because there is realistically no way to know if a component is used twice (or the same ID used in a different component), this is incorrect and probably unfixable.
What to do with this? My proposal would be to change the default value of the style
config from ["type", "id", "class"]
to ["type", "class"]
, which actually promotes class selectors over ID selectors. Additionally, I'd add a note to the docs. @ota-meshi @baseballyama what do you think? Is this OK to change in a minor version? I can also remove the ID option altogether for a more thorough solution.... Thanks!