stylelint-plugin-tailwindcss
v3.1.1
Published
Stylelint plugin utilities for Tailwind CSS and utility-first selector rules
Downloads
8,434
Maintainers
Readme
stylelint-plugin-tailwindcss
Stylelint plugin for teams that do not want authored CSS to drift toward utility-first styles.
It focuses on two related policies:
- do not declare utility selectors such as
.flex,.grid,.text-center, or.hover\:bg-red-500in authored CSS - control utility-oriented directives such as
@apply,theme(...),@screen, and similar Tailwind syntax when your team wants stricter stylesheet conventions
Although the package name is Tailwind-oriented, it also ships a parallel
unocss/* namespace so the same stylelint workflow can still be useful in
UnoCSS-style projects.
Installation
pnpm add -D stylelint stylelint-plugin-tailwindcssRuntime-aware rules validate against the consuming project instead of guessing
from class-name prefixes. Tailwind rules resolve the installed tailwindcss
v3 or v4 runtime. UnoCSS rules discover the nearest uno.config.* or
unocss.config.* and use the official UnoCSS generator. If the corresponding
runtime or config is absent, those rules conservatively produce no match.
Quick Start
Use the default recommended preset:
// stylelint.config.ts
import { recommended } from 'stylelint-plugin-tailwindcss'
export default recommendedUse the minimal base preset:
import { base } from 'stylelint-plugin-tailwindcss'
export default baseUse only one namespace:
import {
tailwindRecommended,
tailwindStrict,
unocssRecommended,
unocssStrict,
} from 'stylelint-plugin-tailwindcss'
export default tailwindRecommended
// or
export default unocssRecommended
// or
export default tailwindStrict
// or
export default unocssStrictDisable one namespace while keeping the other:
import { recommended } from 'stylelint-plugin-tailwindcss'
export default {
...recommended,
rules: {
...recommended.rules,
'unocss/no-atomic-class': false,
'unocss/no-invalid-apply': false,
'unocss/no-apply': false,
'unocss/no-arbitrary-value': false,
'unocss/no-variant-group': false,
},
}Presets
base
Lowest-noise starting point. It only enables the core selector and invalid
@apply checks for both namespaces.
tailwindcss/no-atomic-classtailwindcss/no-invalid-applyunocss/no-atomic-classunocss/no-invalid-apply
recommended
Default preset. It enables both namespaces, but only the lower-noise rules that work well as a general recommendation.
Tailwind rules:
tailwindcss/no-atomic-classtailwindcss/no-invalid-applytailwindcss/no-applytailwindcss/no-arbitrary-valuetailwindcss/no-invalid-theme-function
UnoCSS rules:
unocss/no-atomic-classunocss/no-invalid-applyunocss/no-applyunocss/no-arbitrary-valueunocss/no-variant-group
tailwindBase
Tailwind-only version of base.
tailwindRecommended
Tailwind-only version of recommended.
strict
Highest policy layer. It adds the more architecture-oriented Tailwind rules on
top of recommended.
Tailwind rules:
tailwindcss/no-atomic-classtailwindcss/no-invalid-applytailwindcss/no-applytailwindcss/no-arbitrary-valuetailwindcss/no-theme-functiontailwindcss/no-invalid-theme-functiontailwindcss/no-screen-directivetailwindcss/no-tailwind-directivetailwindcss/no-import-directivetailwindcss/no-css-layer
UnoCSS rules:
unocss/no-atomic-classunocss/no-invalid-applyunocss/no-applyunocss/no-arbitrary-valueunocss/no-variant-group
tailwindStrict
Tailwind-only version of strict.
unocssBase
UnoCSS-only version of base.
unocssRecommended
UnoCSS-only version of recommended.
unocssStrict
UnoCSS-only version of strict.
At the moment it is intentionally the same as unocssRecommended.
What Gets Reported
Reported utility selectors include examples such as:
.flex.grid.text-center.hover\:bg-red-500.md\:flex.\!mt-4.w-\[10px\]
Semantic selectors such as these are not treated as utility selectors:
.page-shell.card__body.hero-banner--primary.table-and-form.flex-layout.rounded-card
Detection Modes
Tailwind runtime
When the consuming project installs Tailwind, the plugin resolves that project’s
own tailwindcss package and validates against the real runtime.
If Tailwind cannot be resolved from the linted file, runtime-dependent rules
such as tailwindcss/no-atomic-class and tailwindcss/no-invalid-apply do not
guess from utility-like prefixes.
UnoCSS runtime
UnoCSS rules search upward from the linted file for uno.config.* or
unocss.config.*, then validate candidates with @unocss/core. Without a
config, runtime-dependent UnoCSS rules produce no match.
When both namespaces recognize the same authored selector, the combined presets report it once.
Rule Reference
Tailwind rules
tailwindcss/no-atomic-classReports authored utility selectors.tailwindcss/no-invalid-applyReports@applycandidates that look utility-like but are not recognized as valid Tailwind utilities.tailwindcss/no-applyReports every@applydirective.tailwindcss/no-arbitrary-valueReports Tailwind-style arbitrary values and arbitrary properties in selectors and@apply, such asw-[10px]and[mask-type:luminance].tailwindcss/no-invalid-theme-functionReportstheme(...)calls whose lookup path is invalid for the resolved Tailwind runtime.tailwindcss/no-theme-functionReports alltheme(...)calls. Exported, but not enabled byrecommended.tailwindcss/no-screen-directiveReports@screen. Exported, but not enabled byrecommended.tailwindcss/no-tailwind-directiveReports@tailwind. Exported, but not enabled byrecommendedbecause it is better suited to migration or architecture-specific presets.tailwindcss/no-import-directiveReports@import "tailwindcss"-style entry imports. Exported, but not enabled byrecommendedbecause it is better suited to migration or architecture-specific presets.tailwindcss/no-css-layerReports authored@layerdirectives. Exported, but not enabled byrecommendedbecause it can also match native CSS cascade layers.
UnoCSS rules
unocss/no-atomic-classReports authored utility selectors.unocss/no-invalid-applyReports@applycandidates that look utility-like but are not recognized as valid candidates by the discovered UnoCSS config and official generator. It is intentionally narrower thanunocss/no-apply: semantic tokens such asbutton-baseare ignored, while misspelled utility-like tokens such asbg-rd-500are reported. Bare-value forms such asw-10pxandtext-rgb(255,0,0)can also be reported here when they fail the validity check.unocss/no-applyReports every@applydirective.unocss/no-arbitrary-valueReports UnoCSS-style arbitrary values in selectors and@apply. This includes bare-value forms such asw-10px,w-50%,top--10px,bg-$brand,text-rgb(255,0,0),translate-x-50%,outline-#fff, and[&>*]:w-10px.unocss/no-variant-groupReports UnoCSS variant groups such ashover:(bg-red-500 text-white).
Exported Names
The package exports:
- preset objects such as
base,recommended,tailwindRecommended, andunocssRecommended - rule names such as
noAtomicClassRuleNameandunocssNoVariantGroupRuleName - plugin instances such as
noAtomicClassPluginandunocssNoVariantGroupPlugin
If you need fine-grained composition, import the individual rule names and plugins directly.
With @icebreakers/stylelint-config
@icebreakers/stylelint-config already wires this plugin in. If you use that
preset, you usually do not need to register this package manually.
Supported File Types
The plugin works anywhere Stylelint works, including:
.css.scss- Vue SFC
<style> - Vue SFC
<style lang="scss">
Demo
This repository includes IDE-friendly examples under
apps/mock/src/stylelint-demo.
More
The stricter preset is documented in
docs/strict-preset.md.
Project links
- Documentation: https://repoctl.icebreaker.top
- Repository: https://github.com/sonofmagic/repoctl/tree/main/packages/stylelint-plugin-tailwindcss
- Issues: https://github.com/sonofmagic/repoctl/issues
