A Stylelint Configuration for Tailwind CSS #19252
theenoahmason
started this conversation in
Show and tell
Replies: 1 comment
-
|
Just released v1.1.2.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello Tailwind gang. We just published a Tailwind CSS Stylelint config that actually implements Tailwind CSS, rather than ignoring its functions and directives. Check it out!
Copying some of the documentation below for reference:
Stylelint Config: Tailwind CSS
A Stylelint configuration for Tailwind CSS projects. This config was developed specifically for Tailwind CSS v4+ and Stylelint v16.17+. This configuration was developed because most of the other popular Stylelint configurations for Tailwind CSS simply ignore directives and functions. Instead, this config implements all Tailwind CSS directives and functions as syntax for Stylelint's language options; so not only can you use them without Stylelint complaining, but Stylelint will actually help to ensure you are using them correctly.
We generate only the syntax needed to override Stylelint's language options to support Tailwind CSS functions and directives. We've added all current Tailwind CSS at-rules,
<--spacing()>and<--alpha>function definitions; and we added<tailwindcss-length>to replace<length>, and<tailwindcss-color>to replace<color>, which instructs stylelint where the spacing and alpha functions can be used respectively. This works by discovering replacement candidates and upgrading syntax from CSS Tree, which is the same package Stylelint uses under the hood.This is accomplished using our
SyntaxGeneratorclass, used through a Rollup plugin. The contents of these files are built to thesyntaxdirectory, then imported and built through rollup into an ESM module and a Common JS module located in thedistdirectory.The contents of these files are passed to Stylelint's
languageOptions.syntaxthrough the config template found atsrc/stylelint.config.mjs. The generation of types, properties, and at-rules allows for automatic upgrading of CSS syntax to accept Tailwind CSS properties where they are accepted in the least destructive and most maintainable way possible.We use a pretty robust set of tests: tests.css
Exports
This package exports both an ESM module and a Common JS module. The default export is the ESM module.
dist/stylelint.config.mjs- ESMdist/stylelint.config.cjs- Common JSGetting started
Install the package
Include in your Stylelint config
Accessing specific keys
You can also decide to spread the imported config onto your stylelint object to extend
languageOptions,languageOptions.syntax,languageOptions.syntax.types,languageOptions.syntax.properties, orlanguageOptions.syntax.atRules. Below is an example of how to fully spread everything provided by this config.Beta Was this translation helpful? Give feedback.
All reactions