ESLint plugin for Tailwind CSS usage
ESLint plugin for Tailwind CSS usage
eslint-plugin-tailwindcssv3 to v4I spent countless days working on this plugin, and it is available to everyone for free.
If you benefit from my work and if you want to help me keep the project alive, consider becoming a sponsor.
| Premium sponsors | Current sponsors |
|---|---|
GitHub Sponsors | thanks.dev Sponsors
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-canonical-classname | Enforces the canonical spelling of a classname, as resolved by the Tailwind CSS compiler. | ✅ | |||
| enforces-negative-arbitrary-values | Warns about - prefixed classnames using arbitrary values. |
✅ | |||
| enforces-shorthand | Avoid using multiple Tailwind CSS classnames when not required. | ✅ | |||
| important-modifier-suffix | In v4 you should place the ! at the very end of the class name. |
✅ | |||
| 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. | ✅ |
npm i -D eslint-plugin-tailwindcss
pnpmIf you are still using Tailwind CSS v3 and/or older ESLint versions, you can use
[email protected]
eslint.config fileHere is a very basic example:
…
cssConfigPathcan be an absolute or a relative path. If you provide a relative path, the plugin will attempt to convert it into an absolute path.
The plugin also exports the type PluginSettings which you can use to benefit from autocomplete and validation directly inside your eslint.config file.
// @ts-check to force type checking/** @type {import('eslint-plugin-tailwindcss').PluginSettings} */Here is a snippet, notice the object is surrounded by parentheses ({...}):
settings: {
tailwindcss:
/** @type {import('eslint-plugin-tailwindcss').PluginSettings} */
({
cssConfigPath: './styles/tailwind.css',
}),
},You can also:
Most of the rules solely use the shared settings (shared across all the plugin rules). Learn about eslint shared settings from the official documentation.
Here is a fully detailed example of shared settings:
…The default settings are exported via the DEFAULT_SETTINGS.
The project is open to all developers, you can contribute to eslint-plugin-tailwindcss.
However, make sure to discuss the issue or the feature you wish to implement prior to getting to work unless you feel adventurous.
No open issues yet, or sync has not completed.