Installations
npm install eslint-plugin-tailwindcss
Score
77
Supply Chain
98.1
Quality
86.1
Maintenance
100
Vulnerability
99.3
License
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
>=18.12.0
Typescript Support
No
Node Version
20.10.0
NPM Version
10.2.3
Statistics
1,516 Stars
387 Commits
72 Forks
8 Watching
16 Branches
31 Contributors
Updated on 28 Nov 2024
Languages
JavaScript (99.58%)
CSS (0.36%)
Vue (0.06%)
Total Downloads
Cumulative downloads
Total Downloads
39,594,160
Last day
-1.8%
125,940
Compared to previous day
Last week
3.1%
686,990
Compared to previous week
Last month
7.9%
2,914,703
Compared to previous month
Last year
154.2%
26,484,455
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
eslint-plugin-tailwindcss
Rules enforcing best practices and consistency using Tailwind CSS.
While you can use the official plugin prettier-plugin-tailwindcss
for ordering your classnames...
eslint-plugin-tailwindcss
offers more than 5 other rules, that you can benefit from on top of prettier-plugin-tailwindcss
. Sounds good ? Keep reading 👇
Supported Rules
Learn more about each supported rules by reading their documentation:
classnames-order
: order classnames for consistency and it makes merge conflict a bit easier to resolveenforces-negative-arbitrary-values
: make sure to use negative arbitrary values classname without the negative classname e.g.-top-[5px]
should becometop-[-5px]
enforces-shorthand
: merge multiple classnames into shorthand if possible e.g.mx-5 my-5
should becomem-5
migration-from-tailwind-2
for easy upgrade from Tailwind CSSv2
tov3
. Warning: at the moment you should temporary turn off theno-custom-classname
rule if you want to see the warning frommigration-from-tailwind-2
no-arbitrary-value
: forbid using arbitrary values in classnames (turned off by default)no-custom-classname
: only allow classnames from Tailwind CSS and the values from thewhitelist
optionno-contradicting-classname
: e.g. avoidp-2 p-3
, different Tailwind CSS classnames (pt-2
&pt-3
) but targeting the same property several times for the same variant.no-unnecessary-arbitrary-value
: e.g. replacingm-[1.25rem]
by its configuration based classnamem-5
Using ESLint extension for Visual Studio Code, you will get these messages
You can can the same information on your favorite command line software as well.
🤝 Support eslint-plugin-tailwindcss
🥰 How you can support us? | 💪 They did it! |
---|---|
Premium Sponsors Support us by becoming a sponsor. Become a recurring sponsor | |
Current Sponsors Any amount is appreciated. | |
Past sponsors Even if this is just a one-time thing. Become a backer | |
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 | eslint-plugin-tailwindcss on Twitter |
Latest changelog
- fix: custom classnames rule with VueJS objects within list (by Ericlm 🙏)
- fix: config loading cache
- fix: Avoid re-parsing unchanged CSS files
- fix: AST expression tests for null expressions (by kesor 🙏)
- fix:
no-arbitrary-value
rule is too broad - fix: support
tag.div
andtag(Component)
(by nihalgonsalves 🙏) - feat: support flat config and ESLint 9 (by kazupon 🙏)
- feat: new rule
no-unnecessary-arbitrary-value
🎉 - fix: retro compatibility for older Tailwind CSS (before typescript config)
- fix: composable touch action classnames
- fix:
shadow-md
+shadow-[#color]
can be used together 🤝 - fix:
tabular-nums
andslashed-zero
can be used together 🤝 - fix:
size-*
basedsize
,spacing
,width
andheight
🤓 - fix: there is no
size-screen
😅 - fix: edge cases with whitespace in
enforces-shorthand
(by kachkaev 🙏) - fix: parsing spreads in function call returns(by egorpavlikhin 🙏)
- feat: support for Tailwind CSS 3.4.0
- ci: add github actions workflow (by nihalgonsalves 🙏)
- fix: bg-center mark as conflicting with bg-[image:xxx]
- feat: support enforcing truncate shorthand (by bezbac 🙏)
- fix: parsing spreads in object expressions (by bezbac 🙏)
- fix: do not handle non-ASCII whitespace as separator (by uhyo 🙏)
- fix: prefix support for named group/peer syntax (by bezbac 🙏)
- feat: support tailwind config in typescript (by quesabe 🙏)
You may have to upgrade your Tailwind CSS version to
3.3.2
Screencasts on our YouTube Channel
ESLint plugin Tailwind CSS youtube.com/@eslint-plugin-tailwindcss |
---|
Installation
1. Install eslint
and eslint-plugin-tailwindcss
You'll first need to install ESLint:
$ npm i -D eslint eslint-plugin-tailwindcss
2. Create Configuration file
.eslintrc
Use .eslintrc.* file to configure rules in ESLint < v9. See also: https://eslint.org/docs/latest/use/configure/.
1module.exports = { 2 root: true, 3 extends: ["plugin:tailwindcss/recommended"], 4};
If you would like to know about configuration, Learn more in ESLint docs
eslint.config.js
Use eslint.config.js
file to configure rules. This is the default in ESLint v9, but can be used starting from ESLint v8.57.0. See also: https://eslint.org/docs/latest/use/configure/configuration-files-new.
1import tailwind from "eslint-plugin-tailwindcss"; 2 3export default [...tailwind.configs["flat/recommended"]];
If you would like to know about configuration, Learn more in ESLint docs
3. Configure ESLint parsers
Depending on the languages you are using in your project you must tell which parser will analyze your source files.
Our recommendations:
For .eslintrc
- For
js[x]
,react
,ts[x]
:- Install the parser:
npm i -D @typescript-eslint/parser
- Assign it to your files in
eslintrc
:1overrides: [ 2 { 3 files: ['*.ts', '*.tsx', '*.js'], 4 parser: '@typescript-eslint/parser', 5 }, 6],
- Install the parser:
- For
vue.js
:- Install the parser:
npm i -D vue-eslint-parser
- Assign it to your files in
eslintrc
:1overrides: [ 2 { 3 files: ['*.vue'], 4 parser: 'vue-eslint-parser', 5 }, 6],
- Install the parser:
- For
HTML
and similar:- Install the parser:
npm i -D @angular-eslint/template-parser
- Assign it to your files in
eslintrc
:1overrides: [ 2 { 3 files: ['*.html', '*.blade.php'], 4 parser: '@angular-eslint/template-parser', 5 }, 6],
- Install the parser:
We removed the default parsers which were added to
v3.8.2
because it created negative impact on dependencies resolution, bundle size increase and possible conflicts with existing configurations.
For eslint.config.js
-
For
js[x]
,ts[x]
:-
Install the parser:
npm i -D @eslint/js typescript-eslint
-
Assign it to your files in
eslint.config.js
:1import js from "@eslint/js"; 2import ts from "typescript-eslint"; 3import tailwind from "eslint-plugin-tailwindcss"; 4 5export default [ 6 // add eslint built-in 7 js.configs.recommended, 8 // add `typescript-eslint` flat config simply 9 // if you would like use more another configuration, 10 // see the section: https://typescript-eslint.io/getting-started#details 11 ...ts.configs.recommended, 12 ...tailwind.configs["flat/recommended"], 13];
-
-
For
vue.js
:-
Install the parser:
npm i -D eslint-plugin-vue
-
Assign it to your files in
eslint.config.js
:1import vue from "eslint-plugin-vue"; 2import tailwind from "eslint-plugin-tailwindcss"; 3 4export default [ 5 // add `eslint-plugin-vue` flat config simply 6 // if you would like use more another configuration, 7 // see the section: https://eslint.vuejs.org/user-guide/#bundle-configurations-eslint-config-js 8 ...vue.configs["flat/recommended"], 9 ...tailwind.configs["flat/recommended"], 10];
-
4. Add a npm script
In your package.json
add one or more script(s) to run eslint targeting your source files:
1"scripts": { 2 "lint": "eslint ./src", 3 "lint:debug": "eslint ./src --debug", 4 "lint:fix": "eslint ./src --fix" 5},
5. Run the linting task
npm run lint
can do the job on demand but you can also get live feedback using VS Code ESLint extension, just make sure you restart VS Code as it can be required for the plugin to work as expected.
More settings
The rules accept settings meant to fit your own choices, make sure to read the documentation of each rule.
Optional shared settings
Most rules share the same settings, instead of duplicating the options all over the place...
You should define the shared settings that will be shared across all the plugin rules.
All these settings already have nice default values that are explained in the documentation.
For .eslintrc
FYI, here are the default
values:
1{ 2 settings: { 3 tailwindcss: { 4 // These are the default values but feel free to customize 5 callees: ["classnames", "clsx", "ctl"], 6 config: "tailwind.config.js", // returned from `loadConfig()` utility if not provided 7 cssFiles: [ 8 "**/*.css", 9 "!**/node_modules", 10 "!**/.*", 11 "!**/dist", 12 "!**/build", 13 ], 14 cssFilesRefreshRate: 5_000, 15 removeDuplicates: true, 16 skipClassAttribute: false, 17 whitelist: [], 18 tags: [], // can be set to e.g. ['tw'] for use in tw`bg-blue` 19 classRegex: "^class(Name)?$", // can be modified to support custom attributes. E.g. "^tw$" for `twin.macro` 20 }, 21 }, 22}
For eslint.config.js
1import tailwind from "eslint-plugin-tailwindcss"; 2 3export default [ 4 ...tailwind.configs["flat/recommended"], 5 { 6 settings: { 7 tailwindcss: { 8 // These are the default values but feel free to customize 9 callees: ["classnames", "clsx", "ctl"], 10 config: "tailwind.config.js", // returned from `loadConfig()` utility if not provided 11 cssFiles: [ 12 "**/*.css", 13 "!**/node_modules", 14 "!**/.*", 15 "!**/dist", 16 "!**/build", 17 ], 18 cssFilesRefreshRate: 5_000, 19 removeDuplicates: true, 20 skipClassAttribute: false, 21 whitelist: [], 22 tags: [], // can be set to e.g. ['tw'] for use in tw`bg-blue` 23 classRegex: "^class(Name)?$", // can be modified to support custom attributes. E.g. "^tw$" for `twin.macro` 24 }, 25 }, 26 }, 27];
The plugin will look for each setting in this order and stops searching as soon as it finds the settings:
- In the rule option argument (rule level)
- In the shared settings (plugin level)
- Default value of the requested setting (plugin level)...
Upcoming Rules
-
validate-modifiers
: I don't know if possible, but I'd like to make sure all the modifiers prefixes of a classname are valid e.g.yolo:bg-red
should throw an error... -
no-redundant-variant
: e.g. avoidmx-5 sm:mx-5
, no need to redefinemx
insm:
variant as it uses the same value (5
) -
only-valid-arbitrary-values
:- e.g. avoid
top-[42]
, only0
value can be unitless. - e.g. avoid
text-[rgba(10%,20%,30,50%)]
, can't mix%
and0-255
.
- e.g. avoid
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/francoismassart/eslint-plugin-tailwindcss/build.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/francoismassart/eslint-plugin-tailwindcss/build.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/francoismassart/eslint-plugin-tailwindcss/build.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/francoismassart/eslint-plugin-tailwindcss/build.yml/master?enable=pin
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
Found 5/28 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/build.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 10 are checked with a SAST tool
Score
3.7
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to eslint-plugin-tailwindcss
@types/eslint-plugin-tailwindcss
TypeScript definitions for eslint-plugin-tailwindcss
@hasparus/eslint-plugin-tailwindcss
Rules enforcing best practices while using Tailwind CSS
prettier-plugin-tailwindcss
A Prettier plugin for sorting Tailwind CSS classes.
@typescript-eslint/eslint-plugin
TypeScript plugin for ESLint