Skip to content

Latest commit

 

History

History
68 lines (46 loc) · 2.24 KB

no-duplicate-classes.md

File metadata and controls

68 lines (46 loc) · 2.24 KB

readable-tailwind/no-duplicate-classes

Disallow duplicate classes in tailwindcss class strings.


Options

  • classAttributes

    The name of the attribute that contains the tailwind classes. This can also be set globally via the [settings object](../settings/settings.md.

    Type: Array of Name, Regex or Matchers
    Default: Name for "class" and strings Matcher for "class", "className"


  • callees

    List of function names which arguments should also get linted. This can also be set globally via the [settings object](../settings/settings.md.

    Type: Array of Name, Regex or Matchers
    Default: Matchers for "cc", "clb", "clsx", "cn", "cnb", "ctl", "cva", "cx", "dcnb", "objstr", "tv", "twJoin", "twMerge"


  • variables

    List of variable names which initializer should also get linted. This can also be set globally via the [settings object](../settings/settings.md.

    Type: Array of Name, Regex or Matchers
    Default: strings Matcher for "className", "classNames", "classes", "style", "styles"


Examples

// ❌ BAD: duplicate classes
<div class="rounded underline rounded" />;
// ✅ GOOD: no duplicate classes
<div class="rounded underline" />;

Note

This rule is smart. It is able to detect duplicates across template literal boundaries.

// ❌ BAD: duplicate classes in conditional template literal classes and around template elements
<div class={`
  underline italic
  ${someCondition === true ? "rounded  underline font-bold" : "rounded underline font-thin"}
  italic
`} />;
// ✅ GOOD: no duplicate classes
<div class={`
  underline italic
  ${someCondition === true ? "rounded  font-bold" : "rounded font-thin"}
`} />;