Shared stylelint config for UXF frontend projects on Tailwind CSS 3. It checks that the CSS is valid and keeps the layout of a rule that oxfmt does not: the order of what is in it and the empty lines between the groups. oxc has no CSS linter, so stylelint stays next to oxlint.
stylelint-config-recommended: unknown properties,
values, at-rules, selectors and functions, duplicates, invalid media queries, deprecated properties and keywords,@tailwind, @apply, @layer, @config, @screen, @variants, @responsive and theme() are
known, as stylelint-config-tailwindcss 0.0.7 sets them, and the prelude of @apply is not parsed as CSS,:global is a known pseudo-class,-webkit-, -ms-…) in properties, values, selectors, at-rules and media features:
autoprefixer adds the ones the browserslist needs,margin: 1px 1px → margin: 1px), longhands a shorthand can replace, nested
rules that repeat their parent,csstools/use-nesting from stylelint-use-nesting: a rule that can be nested in its parent is nested (.a:hover
inside .a), with an autofix,no-descending-specificity and selector-type-no-unknown are off, as they were in every UXF project config.
.uxf-checkbox {
--uxf-checkbox-selected-color: theme("colors.primary.DEFAULT");
@apply transition focus-visible:before:border-2;
align-items: center;
background-color: theme("colors.white");
border: 1px solid theme("colors.gray.400");
&:hover {
background-color: theme("colors.gray.100");
}
}
@apply, which UXF CSS is moving away from, and whatever mixin syntax replaces it,order/order and order/properties-alphabetical-order from stylelint-order check 1–3. The alphabetical order is what
prettier-plugin-css-order with cssDeclarationSorterOrder: "alphabetical" did in UXF projects, and oxfmt does not do.
The empty lines are the rules of stylelint-config-standard 40: one before each group and before a nested rule or a
comment, none before the first item of a block. oxfmt keeps an empty line where there is one, collapses several into
one and never adds one. All of it is fixed by stylelint --fix.
@apply to the top--fix moves an @apply above the declarations written before it. That changes the result only when such a
declaration sets a property the @apply sets too: before the move the @apply wins, after it the declaration does.
Prettier sorted each run of declarations between two at-rules on its own, so this order is new to every project. In
the fe-monorepo 26 rules moved and none of them had such a declaration; in seven projects 14 rules moved, none either
(three @apply of a project's own classes could not be checked). The check expanded every @apply with the project's
Tailwind config and compared the properties it sets with the declarations moved across it.
Of the rules stylelint-config-standard adds to the recommended set:
rgb() instead of rgba(), 0 instead of 0px, short hex colours, quotes in url() and font names,
keyword case),yarn add -D @uxf/stylelint-config stylelint
stylelint ^17.16.0 is a peer dependency (yarn dependencies:fix installs it in a project with @uxf/scripts).
stylelint-config-recommended, stylelint-order and stylelint-use-nesting come with this package, so a project that switches removes
its own:
yarn remove stylelint-config-standard stylelint-config-tailwindcss stylelint-use-nesting postcss-syntax
Keep postcss-syntax if something other than stylelint uses it. The config sets no customSyntax: stylelint parses
.css files on its own, and postcss-syntax picked the same parser for them.
// stylelint.config.mjs
export { default } from "@uxf/stylelint-config";
A project adds its own rules on top. The fe-monorepo checks custom properties against its token files:
// stylelint.config.mjs
import uxfStylelintConfig from "@uxf/stylelint-config";
import stylelintValueNoUnknownCustomProperties from "stylelint-value-no-unknown-custom-properties";
export default {
extends: [uxfStylelintConfig],
plugins: [stylelintValueNoUnknownCustomProperties],
rules: {
"csstools/value-no-unknown-custom-properties": [true, { importFrom: ["src/styles/tokens.css"] }],
},
};
The scripts stay as they are:
{
"stylelint:check": "stylelint \"./**/*.(css)\"",
"stylelint:fix": "stylelint \"./**/*.(css)\" --fix"
}
Before the release, the config ran next to each project's own on twelve projects (web and backoffice packages,
284 CSS files), both on stylelint 17.16.0. Nothing new in four (jablonec-365 web and backoffice, uxf-base/web,
tur/web). The rest is order, all of it fixed by --fix, except in one project:
kalkulator/web: 17 issues the project's config did not check, because its overrides glob missed nested files
(unnested rules, a deprecated clip, an empty block, two vendor prefixes), 69 order and 52 empty-line reports,booking-engine/backoffice: 4 declarations out of alphabetical order,atrea-acu, booking-engine/web, centropol-monitor, lumo-app, rehatab, rovernet (web): 1–4 order reports
each, mostly a custom property or an @apply below a declaration.Two projects whose config predates stylelint 17.16 report the prelude of @apply as invalid on 17.16; this config
does not.
stylelint-config-recommended 19 needs it, and most projects are on 17. A project already on 18
(atrea-acu) waits for the release that moves this package to it.@media screen(md), Tailwind 3's screen() in a media query, is reported by media-query-no-invalid, as it was
with stylelint-config-standard. Use @screen md or turn the rule off in the project.@theme, @utility, @variant, @custom-variant, @source, @plugin, @reference), which no
UXF project uses yet.