Skip to content

Add rule consistent-selector-style #898

Closed
@marekdedic

Description

@marekdedic

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 reduction

Description

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

<a class="link">Text 1</a>

<b class="bold">Text 2</b>
<b class="bold">Text 3</b>

<i class="italic">Text4</i>
<i>Text5</i>

<style>
  /* ✗ BAD */
  .link {}
  .bold {}

  /* ✓ GOOD */
  .italic {}
</style>

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions