-
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rule consistent-selector-style
#898
Comments
Thank you for the rule proposal. |
Hi, I still see the value of having such a rule for those who want it. At the same time, I don't think the rule should ever be in the recommended set, that is for sure. What do you think? |
Yeah, I think it's fine to have rules in this plugin if they can satisfy various preferences. Do you have any ideas? |
Hmm, so something like The trouble is, not all selectors are applicable in all situations - classes are I think universal, but there can only be one instance of a particular ID and tag selectors can only be used if there aren't any duplicate tags. I can envision having an ordered list of preferences, so that with a list <a class="one"></a>
<a class="one two"></a>
<b class="three"></b>
<i class="three"></i>
<style>
.one {} /* Error, use tag name */
.two {} /* Error, use id */
.three {} /* Ok */
</style> This is only a rough sketch and there are more different selectors, but what do you think about this general idea? |
Thanks for your comment. |
consistent-selector-style
Motivation
When styling elements in Svelte components, there are many options for referencing said elements. The simplest one, leading to the least amount of code is to simply refer to them by their tag name. I'd like to add a rule that enforces this if it is possible (i.e. if there are no duplicates of said element). This may dovetail nicely with
no-unused-class-name
and lead to code reductionDescription
For each CSS selector using a class, the rule would check the tag name for the element the class is referring to. If there aren't multiple elements with that same tag (or they all share the same class), the rule would trigger and recommend selecting by the tag name instead. The same would apply to IDs
Examples
Additional comments
No response
The text was updated successfully, but these errors were encountered: