Security News
Python Overtakes JavaScript as Top Programming Language on GitHub
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
eslint-plugin-tailwindcss
Advanced tools
eslint-plugin-tailwindcss is an ESLint plugin that provides linting rules for Tailwind CSS classes. It helps ensure that Tailwind CSS classes are used correctly and consistently in your project.
Class Order
This feature ensures that Tailwind CSS classes are ordered correctly. It helps maintain a consistent order of classes, which can improve readability and maintainability.
module.exports = {
plugins: ['tailwindcss'],
rules: {
'tailwindcss/classnames-order': 'warn'
}
};
No Custom Classnames
This feature disallows the use of custom class names that are not part of the Tailwind CSS framework. It ensures that only Tailwind CSS classes are used, which can help prevent styling issues.
module.exports = {
plugins: ['tailwindcss'],
rules: {
'tailwindcss/no-custom-classname': 'error'
}
};
No Arbitrary Value
This feature disallows the use of arbitrary values in Tailwind CSS classes. It ensures that only predefined values are used, which can help maintain consistency and prevent errors.
module.exports = {
plugins: ['tailwindcss'],
rules: {
'tailwindcss/no-arbitrary-value': 'error'
}
};
eslint-plugin-css-modules is an ESLint plugin that provides linting rules for CSS Modules. It helps ensure that CSS Modules are used correctly and consistently in your project. Unlike eslint-plugin-tailwindcss, which focuses on Tailwind CSS, eslint-plugin-css-modules is designed for projects using CSS Modules.
stylelint is a powerful, modern linter that helps you avoid errors and enforce conventions in your styles. While eslint-plugin-tailwindcss is specifically for Tailwind CSS, stylelint can be used with any CSS framework or custom CSS. It offers a wide range of rules and is highly configurable.
eslint-plugin-styled-components-a11y is an ESLint plugin that provides accessibility linting rules for styled-components. It helps ensure that styled-components are used in an accessible way. While eslint-plugin-tailwindcss focuses on Tailwind CSS, eslint-plugin-styled-components-a11y is designed for projects using styled-components.
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.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 |
3.3.2
ignoredKeys
in settings used for cva
or similarno-custom-classname
doesn't work with hyphenated group namesclassRegex
ignored in vuejsv-bind:class
recommended
preset and dependencies
vue-eslint-parser
as default parser for *.vue
filesrecommended
presettailwindcss
to peerDependencies
(by xeho91 🙏)classnames
(by dipsaus9 🙏)skipClassAttribute
you can turn on to only lint the callees
3.2.3
ESLint plugin Tailwind CSS youtube.com/@eslint-plugin-tailwindcss |
---|
eslint
You'll first need to install ESLint:
$ npm i -D eslint
Then, create you .eslintrc.js
file
module.exports = {
root: true,
};
eslint-plugin-tailwindcss
$ npm i -D eslint-plugin-tailwindcss
Edit your .eslintrc
file to use our recommended
preset to get reasonable defaults:
module.exports = {
root: true,
extends: ["plugin:tailwindcss/recommended"],
};
If you do not use our preset you will need to specify individual rules and add extra configuration...
Learn more about Configuring Rules in ESLint.
Depending on the languages you are using in your project you must tell which parser will analyze your source files.
Our recommendations:
js[x]
, react
, ts[x]
:
npm i -D @typescript-eslint/parser
eslintrc
:
overrides: [
{
files: ['*.ts', '*.tsx', '*.js'],
parser: '@typescript-eslint/parser',
},
],
vue.js
:
npm i -D vue-eslint-parser
eslintrc
:
overrides: [
{
files: ['*.vue'],
parser: 'vue-eslint-parser',
},
],
HTML
and similar:
npm i -D @angular-eslint/template-parser
eslintrc
:
overrides: [
{
files: ['*.html', '*.blade.php'],
parser: '@angular-eslint/template-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.
In your package.json
add one or more script(s) to run eslint targeting your source files:
"scripts": {
"lint": "eslint ./src",
"lint:debug": "eslint ./src --debug",
"lint:fix": "eslint ./src --fix"
},
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.
FYI, here are the default
values:
{
settings: {
tailwindcss: {
// These are the default values but feel free to customize
callees: ["classnames", "clsx", "ctl"],
config: "tailwind.config.js", // returned from `loadConfig()` utility if not provided
cssFiles: [
"**/*.css",
"!**/node_modules",
"!**/.*",
"!**/dist",
"!**/build",
],
cssFilesRefreshRate: 5_000,
removeDuplicates: true,
skipClassAttribute: false,
whitelist: [],
tags: [],
classRegex: "^class(Name)?$", // can be modified to support custom attributes. E.g. "^tw$" for `twin.macro`
},
},
}
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
.FAQs
Rules enforcing best practices while using Tailwind CSS
The npm package eslint-plugin-tailwindcss receives a total of 665,180 weekly downloads. As such, eslint-plugin-tailwindcss popularity was classified as popular.
We found that eslint-plugin-tailwindcss demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
Security News
Dutch National Police and FBI dismantle Redline and Meta infostealer malware-as-a-service operations in Operation Magnus, seizing servers and source code.
Research
Security News
Socket is tracking a new trend where malicious actors are now exploiting the popularity of LLM research to spread malware through seemingly useful open source packages.