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

Package detail

eslint-plugin-readable-tailwind

schoero23.2kMIT1.9.1TypeScript 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 jsx, svelte, vue, and html files.



[!NOTE] Support for tailwindcss v4 is currently in beta.

If you are on tailwindcss v4, install the beta version of this plugin: npm i -D eslint-plugin-readable-tailwind@beta. Please report any feedback or issues you encounter with the beta version in the discussions. Additional breaking changes are documented in the CHANGELOG on the v2 branch.



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. Read the Rules section to learn about the available rules and how to configure them.
  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

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)