Skip to content

[Feature request] New rule: no-unnecessary-arbitrary-value #175

@threehams

Description

@threehams

Is your feature request related to a problem? Please describe.
I'm working on a team of about 30 people on a medium-sized codebase. It's common to see an arbitrary value like this:

text-[14px]

This is exactly the same as:

text-md

However, it creates duplicate CSS. Over time, this adds up to a significant amount of extra CSS for no benefit.

Describe the solution you'd like
Detect when an arbitrary value is identical to a configured value, and offer to replace it.

bg-[#f8f8f8]
// fixes to
bg-light
text-[var(--gray)]
// fixes to
text-dark

This is all dependent on the project's configuration.

Out of scope:

  • Similar (but not exact) colors are not flagged. Only exact matches are done.
  • No unit conversion is done to/from rem/px, for example.

Describe alternatives you've considered

  1. The current rule is no-arbitrary-value, but that shuts them off completely.
  2. More granularity on no-arbitrary-value. There are specific things that tend to get duplicated, like text-, bg-, and border-. Disabling arbitrary values on these could help prevent these from spreading.
  3. Instead of going completely for the "all values", make a very targeted rule for the most common offenders.

**Risks:
Arbitrary values come later in the stylesheet, so a fixer will not be 100% safe to run. However, these should already be considered bugs, hopefully caught by no-contradicting-classname.

Additional context
I'm working on this right now for a private project, so I'll get it done regardless in the next couple weeks, but I thought it may be useful to have it more broadly available.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions