Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-readable-tailwind

schoero34.6kMIT2.1.0TypeScript support: included

auto-wraps tailwind classes after a certain print width or class count into multiple lines to improve readability.

eslint, eslint-plugin, tailwind, readable, horizontal, scrolling, multiline, multi, newline, line, break, linebreak, wrap, template, literal, jsx, html, svelte, vue, react, qwik, solid, template-literal, template-literals, tailwindcss, tailwind-css, tailwind-classes

readme

<picture> <source media="(prefers-color-scheme: dark)" srcset="./assets/eslint-plugin-readable-tailwind-logo-dark.svg"> <source media="(prefers-color-scheme: light)" srcset="./assets/eslint-plugin-readable-tailwind-logo-light.svg"> eslint-plugin-readable-tailwind logo </picture>

readable-tailwind



<picture> <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/license/schoero/eslint-plugin-readable-tailwind?style=flat-square&labelColor=32363B&color=ffffff"> <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/license/schoero/eslint-plugin-readable-tailwind?style=flat-square&labelColor=EBEEF2&color=000000"> eslint-plugin-readable-tailwind logo </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/eslint-plugin-readable-tailwind?style=flat-square&labelColor=32363B&color=ffffff"> <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/npm/v/eslint-plugin-readable-tailwind?style=flat-square&labelColor=EBEEF2&color=000000"> eslint-plugin-readable-tailwind logo </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/issues/schoero/eslint-plugin-readable-tailwind?style=flat-square&labelColor=32363B&color=ffffff"> <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/issues/schoero/eslint-plugin-readable-tailwind?style=flat-square&labelColor=EBEEF2&color=000000"> eslint-plugin-readable-tailwind logo </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/dt/eslint-plugin-readable-tailwind?style=flat-square&labelColor=32363B&color=ffffff"> <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/npm/dt/eslint-plugin-readable-tailwind?style=flat-square&labelColor=EBEEF2&color=000000"> eslint-plugin-readable-tailwind logo </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/stars/schoero/eslint-plugin-readable-tailwind?style=flat-square&labelColor=32363B&color=ffffff"> <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/stars/schoero/eslint-plugin-readable-tailwind?style=flat-square&labelColor=EBEEF2&color=000000"> eslint-plugin-readable-tailwind logo </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/actions/workflow/status/schoero/eslint-plugin-readable-tailwind/ci.yml?event=push&style=flat-square&labelColor=32363B&color=ffffff"> <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/actions/workflow/status/schoero/eslint-plugin-readable-tailwind/ci.yml?event=push&style=flat-square&labelColor=EBEEF2&color=000000"> eslint-plugin-readable-tailwind logo </picture>


ESLint plugin to automatically break up long tailwind class strings into multiple lines based on a specified print width or class count. This improves readability and eliminates horizontal scrolling.
In addition it sorts the classes logically, removes unnecessary whitespaces and duplicate classes and groups the classes by their variants. It works in React, Solid.js, Qwik, Svelte, Vue, Angular, HTML, JavaScript and TypeScript projects.



eslint-plugin-readable-tailwind example


<picture> <source media="(prefers-color-scheme: dark)" srcset="./assets/sponsor-dark.svg"> <source media="(prefers-color-scheme: light)" srcset="./assets/sponsor-light.svg"> eslint-plugin-readable-tailwind logo </picture>

Buy me a coffee | GitHub Sponsors

This project is financed by the community.
If you or your company benefit from this project, please consider becoming a sponsor or making a one-time donation.
Your contribution will help me to maintain and develop the project.



Installation

npm i -D eslint-plugin-readable-tailwind

Quick start

  1. Follow the parsers section below to learn how to configure the plugin for your specific requirements.

  2. Configure the plugin to be able to read your tailwind configuration via settings or for each rule separately.

     // eslint.config.js
     {
       //...
       "settings": {
         "readable-tailwind": {
           // tailwindcss 4: the path to the entry file of the css based tailwind config (eg: `src/global.css`)
           "entryPoint": "src/global.css",
           // tailwindcss 3: the path to the tailwind config file (eg: `tailwind.config.js`)
           "tailwindConfig": "tailwind.config.js"
         }
       }
     }
  3. Configure your editor to conveniently auto-fix on save.



Parsers

Depending on the flavor you are using, you may need to install and configure the corresponding parser:



Rules

Two predefined configurations are available that contain the recommended rules:

  • error - will throw an error if the rule is violated
  • warning - will throw a warning if the rule is violated

The following table shows the available rules and if they are enabled by default in the different configurations:

Name Description error warning autofix
multiline Enforce consistent line wrapping for tailwind classes.
no-unnecessary-whitespace Disallow unnecessary whitespace in tailwind classes.
sort-classes Enforce a consistent order for tailwind classes.
no-duplicate-classes Remove duplicate classes.


Utilities

This plugin works out of the box with most popular tailwind utilities:



In case an utility is not supported or you have built your own, you can change which literals will get linted for each rule. Read the API documentation to learn how to override or extend the default config.



Editor configuration

VSCode

Auto-fix on save

All rules are intended to automatically fix the tailwind classes. If you have installed the VSCode ESLint plugin, you can configure it to automatically fix the classes on save by adding the following options to your .vscode/settings.json:

{
  // enable ESLint to fix tailwind classes on save
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit"
  }
}


changelog

Changelog

v2.1.0

compare changes

Features

Experimental angular support. (#85)

  • Keep carriage return in es literals when used with vue parser (#84)

v2.0.1

compare changes

Fixes

  • Keep original newline characters (a564783)

Refactors

  • Display warning if plugin is misconfigured (7c532cd)

Documentation

  • Update quick start guide (e570981)

v2.0.0

Adds tailwindcss v4 support while keeping support for tailwindcss v3. (#78)

This version contains breaking changes. Most notably support for Node.js < 20 had to be dropped. The other breaking changes are mostly just changes of the default config, that may cause linting errors.

Migration

  • If you use tailwindcss v4, you should specify the entryPoint of the css based tailwind configuration file for the sort-classes rule or in the settings.
  • If you have customized the classAttributes option for any of the rules or via the settings, rename the option to attributes
  • If you have customized attributes, callees, variables, or tags, escape any reserved characters for regular expressions in the name as the name is now evaluated as a regular expression.

    For example:

     {
       variables: [
    -    "$MyVariable"
    +    "\\$MyVariable"
       ]
     }

Changes

  • Reload tailwind config automatically if a change is detected.
  • Options now correctly override settings (#66)

⚠️ Breaking Changes

  • ⚠️ Drop support for Node.js < 20 due to incompatibility of worker threads.
  • ⚠️ Add support for tailwindcss v4 (#25)

    • The official class ordering seems to have changed slightly.
    • The improved sorting order will no longer sort variants alphabetically, instead it just makes sure that identical variants are grouped together.
  • ⚠️ Regex names (#63)

    • "Names" can now be regular expressions. This is a breaking change, if you have names configured that contain reserved characters in regular expressions like $.
  • ⚠️ Enable no-duplicate-classes by default (#67)
  • ⚠️ Change default multiline grouping to newLine (#68)
  • ⚠️ Rename classAttributes to attributes (#69)

v1.9.1

compare changes

Fixes

  • Lint className in render functions inside object (#75)

v1.9.0

compare changes

Features

  • Template literal tags (#65)

v1.8.2

compare changes

Fixes

  • Fixing loop when lines wrap on two lines immediately but was theoretically short enough to not wrap (#61)

v1.8.1

compare changes

Refactors

  • Improve display of linting errors (#60)

v1.8.0

compare changes

Features

  • Add support to globally configure shared options across all rules via the settings object (#56)

v1.7.0

compare changes

Features

  • New option preferSingleLine (#54)

v1.6.1

compare changes

Fixes

  • Group type never not working with expressions (#53)

v1.6.0

compare changes

Features

  • New rule no-duplicate-classes (#49)
    This rule will be enabled by default in v2.0.0. If you want to enable it now, please refer to the rule documentation.
    You can suggest additional rules in the discussions.

Refactors

v1.5.3

compare changes

Refactors

  • Insertion of unnecessary escape characters (#47)

v1.5.2

compare changes

Fixes

  • Remove unnecessary plugin import in shared config (#44)
  • Support svelte shorthand syntax (#43)

v1.5.1

compare changes

Fixes

  • Commonjs build (#39)

v1.5.0

compare changes

Features

  • Vue bound classes (#31)

Fixes

  • Change quotes in multiline arrays (#32)
  • Escape nested quotes (#33)
  • Allow call expressions as object values (#34)
  • Attributes are no longer case sensitive (#35)
  • Warn in html matchers (#36)
  • Don't treat escape characters as whitespace (6aa74f8)

Refactors

  • Simplify build system (#26, #29)

v1.4.0

compare changes

Features

  • Matchers (#28)

v1.3.2

compare changes

Fixes

  • Remove unnecessary newline after single sticky class (#23)
  • Prevent inserting new line if the first class is already too long (#24)

Tests

  • Simplify testing (#22)

v1.3.1

compare changes

Fixes

  • Accept tabs (#21)

v1.3.0

compare changes

Features

  • Add eslint 9 support (#19)

Chore

v1.2.5

compare changes

Performance

  • Cache tailwind config and context (#16)

Fixes

  • Resolving tailwind config (#15)

v1.2.4

compare changes

Fixes

  • Sticky expressions (#13)

v1.2.3

compare changes

Fixes

  • Remove unnecessary trailing spaces in multiline strings (#12)
  • False positives when using crlf (#11)

v1.2.2

compare changes

Fixes

  • False positives of unnecessary whitespace around template literal elements (#9)

v1.2.1

compare changes

Fixes

  • Don't wrap empty attributes (#8)

v1.2.0

compare changes

Features

  • Lint variables (#7)

Fixes

  • Apply nested regex only to container groups (#6)

v1.1.1

compare changes

Fixes

  • Invalid collapsing with template literal expressions (adfafbf)

v1.1.0

compare changes

Features

  • Collapse unnecessary newlines (#4)
  • Regex as callees (#3)