JSPM

eslint-plugin-tailwindcss

4.0.0-alpha.6
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1504892
  • Score
    100M100P100Q190630F
  • License MIT

Rules enforcing best practices while using Tailwind CSS

Package Exports

  • eslint-plugin-tailwindcss
  • eslint-plugin-tailwindcss/package.json

Readme

eslint-plugin-tailwindcss

eslint-plugin-tailwindcss logo

Rules

💼 Configurations enabled in.
⚠️ Configurations set to warn in.
✅ Set in the recommended configuration.
🔧 Automatically fixable by the --fix CLI option.
💡 Manually fixable by editor suggestions.

Name Description 💼 ⚠️ 🔧 💡
classnames-order Enforces a consistent order for the Tailwind CSS classnames, based on the compiler. 🔧
enforces-negative-arbitrary-values Warns about - prefixed classnames using arbitrary values. 🔧
enforces-shorthand Avoid using multiple Tailwind CSS classnames when not required. 🔧
no-arbitrary-value Forbid using arbitrary values in classnames.
no-contradicting-classname Avoid contradicting Tailwind CSS classnames. 💡
no-custom-classname Detects classnames which do not belong to Tailwind CSS. 💡
no-unnecessary-arbitrary-value Avoid unjustified arbitrary classnames. 🔧 💡

Settings

You should specify settings that will be shared across all the plugin rules. (More about eslint shared settings)

// eslint.config.mjs
{
  settings: {
    tailwindcss: {
      // Attributes/props that could contain Tailwind CSS classes...
      // Optional, default values: ["class", "className", "ngClass", "@apply"]
      attributes: ["class"],
      // The absolute path pointing to you main Tailwind CSS v4 config file.
      // It must be a `.css` file (v4), not a `.js` file (v3)
      // REQUIRED, default value will not help
      cssConfigPath: dirname(fileURLToPath(import.meta.url)) + "/styles/tailwind.css",
      // Functions/tagFunctions that will be parsed by the plugin.
      // Optional, default values: ["classnames", "clsx", "ctl", "cva", "tv", "tw"]
      functions: ["twClasses"],
      // Keys to be ignored in object expressions
      // Optional, default values: ["defaultVariants", "compoundVariants"]
      ignoredKeys: ["defaultVariants", "compoundVariants", "foo"],
      // Max size of the Set or Map objects used for caching
      // Optional, default value: 250000
      cacheMaxSize: 150_000,
      // Max lifetime of the cache set in ms
      // Optional, default value: 10 * 60 * 1000 (10 minutes)
      cacheMaxAge: 60 * 1000,
    },
  }
}

The default settings are exported via the DEFAULT_SETTINGS.

Made for Tailwind CSS v4

Version 4 of the eslint-plugin-tailwindcss is:

Status

This branch was started back in 2024, and I was quickly stuck while trying to use the internal mechanics of the tailwindcss package.

Simple tasks, like loading the CSS config, was impossible inside an ESLint plugin because ESLint plugins are synchronous by design while the tailwindcss package uses plenty of async functions.

😇 Hopefully, hyoban made tailwind-api-utils and demonstrated in a PR how I could use it via synckit 👏.

Work in progress

This version is far from finished, yet it is available and open for contributions.

All the details are available in the changelog.

Latest completed steps

  • restore the automated tests running on the merge requests of the repo
  • implement and test the usage of tailwind-api-utils
  • read the settings from eslint (shared settings & rules settings)
  • create the config utility
  • implement the classnames-order rule and its tests
  • implement the no-custom-classname rule and its tests

Next steps

  • implement the enforces-negative-arbitrary-values rule and its tests
  • implement the enforces-shorthand rule and its tests
  • implement the no-arbitrary-value rule and its tests
  • implement the no-contradicting-classname rule and its tests
  • implement the no-unnecessary-arbitrary-value rule and its tests

Contributing

The project is open to all developers, you can contribute the eslint-plugin-tailwindcss.

🤝 Support eslint-plugin-tailwindcss

🥰 How you can support us? 💪 They did it!
Premium Sponsors
Support us by becoming a sponsor.
Become a recurring sponsor
Sent.dm
Current Sponsors
Any amount is appreciated.
@codecov @sourcegraph @getsentry
Past sponsors
Even if this is just a one-time thing.
Become a backer
@acewf @hyoban @charkour @aniravi24 @amotarao @mongolyy @t3dotgg @fongandrew @nivalis-studio @jonz94 daily.dev @kylemh @theMosaad
Contributors
This project can evolve thanks to all the people who contribute.
You are welcome to contribute to this project by reporting issues, feature requests or even opening Pull Requests.
Supporters
Talk about the plugin on your social networks
Share the word on Bluesky or Reach my profile