Gathering detailed insights and metrics for eslint-plugin-tailwindcss
Gathering detailed insights and metrics for eslint-plugin-tailwindcss
Gathering detailed insights and metrics for eslint-plugin-tailwindcss
Gathering detailed insights and metrics for 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
npm install eslint-plugin-tailwindcss
77
Supply Chain
98.1
Quality
86.1
Maintenance
100
Vulnerability
99.3
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,516 Stars
387 Commits
72 Forks
8 Watching
16 Branches
31 Contributors
Updated on 28 Nov 2024
JavaScript (99.58%)
CSS (0.36%)
Vue (0.06%)
Cumulative downloads
Total Downloads
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
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 👇
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 become top-[-5px]
enforces-shorthand
: merge multiple classnames into shorthand if possible e.g. mx-5 my-5
should become m-5
migration-from-tailwind-2
for easy upgrade from Tailwind CSS v2
to v3
.
Warning: at the moment you should temporary turn off the no-custom-classname
rule if you want to see the warning from migration-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 the whitelist
optionno-contradicting-classname
: e.g. avoid p-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. replacing m-[1.25rem]
by its configuration based classname m-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.
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 |
no-arbitrary-value
rule is too broadtag.div
and tag(Component)
(by nihalgonsalves 🙏)no-unnecessary-arbitrary-value
🎉shadow-md
+ shadow-[#color]
can be used together 🤝tabular-nums
and slashed-zero
can be used together 🤝size-*
based size
, spacing
, width
and height
🤓size-screen
😅enforces-shorthand
(by kachkaev 🙏)3.3.2
ESLint plugin Tailwind CSS youtube.com/@eslint-plugin-tailwindcss |
---|
eslint
and eslint-plugin-tailwindcss
You'll first need to install ESLint:
$ npm i -D eslint eslint-plugin-tailwindcss
.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
Depending on the languages you are using in your project you must tell which parser will analyze your source files.
Our recommendations:
.eslintrc
js[x]
, react
, ts[x]
:
npm i -D @typescript-eslint/parser
eslintrc
:
1overrides: [ 2 { 3 files: ['*.ts', '*.tsx', '*.js'], 4 parser: '@typescript-eslint/parser', 5 }, 6],
vue.js
:
npm i -D vue-eslint-parser
eslintrc
:
1overrides: [ 2 { 3 files: ['*.vue'], 4 parser: 'vue-eslint-parser', 5 }, 6],
HTML
and similar:
npm i -D @angular-eslint/template-parser
eslintrc
:
1overrides: [ 2 { 3 files: ['*.html', '*.blade.php'], 4 parser: '@angular-eslint/template-parser', 5 }, 6],
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.
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];
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},
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.
The rules accept settings meant to fit your own choices, make sure to read the documentation of each rule.
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.
.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}
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:
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. avoid mx-5 sm:mx-5
, no need to redefine mx
in sm:
variant as it uses the same value (5
)
only-valid-arbitrary-values
:
top-[42]
, only 0
value can be unitless.text-[rgba(10%,20%,30,50%)]
, can't mix %
and 0-255
.No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
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
Reason
Found 5/28 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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 More