Package Exports
- eslint-plugin-tailwindcss
- eslint-plugin-tailwindcss/package.json
Readme
eslint-plugin-tailwindcss
- Best practices & consistency since 2021
- Made for Tailwind CSS v4
- 7 rules available and more on the way
- What's new ? Changelog | Release notes | Roadmap
- Upgrade guide from
v3tov4
This project needs your help
I spent countless days working on this plugin, and it is available to all for free.
If you benefits 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
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. | â | ð§ | ðĄ |
Getting started
1. Install the plugin
npm i -D eslint-plugin-tailwindcss
- As it is a dev dependency, it will not affected your final bundle size ðŠķ
- It can be installed with other package managers such as
pnpm - We support ESLint v10
If you are still using Tailwind CSS v3 and/or older ESLint versions, you can use
eslint-plugin-tailwindcss@3.x.x
2. Edit your eslint.config file
Here is a very basic example:
// 1. import the plugin
import eslintPluginTailwindcss from "eslint-plugin-tailwindcss";
import { defineConfig } from "eslint/config";
export default defineConfig([
{
// 2. Optional: extend an existing config preset
extends: [eslintPluginTailwindcss.configs.recommended],
settings: {
// 3. Define the tailwindcss settings with the MANDATORY cssConfigPath
tailwindcss: {
cssConfigPath: "./src/styles/tailwind.css",
},
},
// 4. Optional: customize the rules to your needs
rules: {
"tailwindcss/classnames-order": "warn",
"tailwindcss/no-arbitrary-value": "warn",
"tailwindcss/no-custom-classname": [
"warn",
{ whitelist: ["custom\\-*"] },
],
"tailwindcss/no-contradicting-classname": "warn",
},
},
]);
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.
3. Going further
You can also:
- run the linting process inside a pipeline of your hosted repository.
- I would recommend to run it on your merge requests
- Not on every single (pre)commit
- autoformat on save in your favorite IDE
Settings
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 detailled example of 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 or relative) 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 may not help
cssConfigPath: "./styles/tailwind.css",
// Functions/tagFunctions that will be parsed by the plugin.
// Optional, default values: ["classnames", "classNames", "clsx", "ctl", "cva", "tv", "tw", "twMerge", "twJoin"]
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: 250_000
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.
Contributing
The project is open to all developers, you can contribute the 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.