/

  • Analyticsnpmv16.3.0

    • Overview
  • Apollonpmv15.2.1ESM

    • Overview
  • Browserslist-confignpmv15.2.1

    • Overview
  • CMSnpmv16.6.0

    • Overview
    • ContentBuilder
    • InviteUserForm
    • LoginForm
    • RenewPasswordForm
    • WysiwygInput
  • Corenpmv16.3.0

    • Overview
  • Core-Reactnpmv16.3.0

    • Overview
  • DataGridnpmv16.6.0

    • Overview
    • DataGrid
    • DataGridCustomExample
    • ExportButton
    • FilterList
    • Filters
    • FiltersButton
    • FulltextInput
    • HiddenColumns
    • HiddenColumnsButton
    • Pagination
    • RowCounts
    • RowsPerPageSelect
    • SelectedRowsToolbar
    • TableV2
    • ToolbarControl
    • ToolbarCustoms
    • ToolbarTabs
  • Datepickernpmv16.3.0

    • Overview
  • DnDnpmv15.2.1

    • Overview
  • E2E-Playwrightnpmv16.6.0

    • Overview
  • Eslint-confignpmv15.2.1

    • Overview
  • Formnpmv16.6.0

    • Overview
    • AvatarFileInput
    • CheckboxButton
    • CheckboxInput
    • CheckboxList
    • ColorRadioGroup
    • Combobox
    • DatePickerInput
    • DateRangePickerInput
    • DatetimePickerInput
    • Dropzone
    • FileInput
    • Form
    • FormRenderer
    • GpsInput
    • MoneyInput
    • MultiCombobox
    • MultiSelect
    • NumberInput
    • PasswordInput
    • RadioGroup
    • Select
    • TextInput
    • Textarea
    • TimePickerInput
    • Toggle
  • Icons-generatornpmv16.3.0

    • Overview
  • Localizenpmv16.3.0

    • Overview
  • Mailingnpmv16.3.0

    • Overview
  • Oxc-confignpmv16.6.0

    • Overview
  • Page-Buildernpmv15.3.0ESM

    • Overview
  • Page-Builder-CMSnpmv16.6.0ESM

    • Overview
  • Page-Builder-Webnpmv16.6.0ESM

    • Overview
  • Resizernpmv15.2.1

    • Overview
  • Routernpmv16.3.0ESM

    • Overview
  • Scriptsnpmv16.6.0

    • Overview
  • Sentrynpmv16.4.0ESM

    • Overview
  • Smart-addressnpmv15.2.1

    • Overview
  • Stylelint-confignpmv16.4.0

    • Overview
  • Stylesnpmv16.3.0

    • Overview
  • UInpmv16.6.0

    • Overview
    • Accordion
    • AlertBubble
    • AnnouncementBar
    • Avatar
    • AvatarFileInput
    • Badge
    • Button
    • ButtonGroup
    • ButtonList
    • Calendar
    • Checkbox
    • CheckboxButton
    • CheckboxInput
    • CheckboxList
    • Chip
    • ColorRadio
    • ColorRadioGroup
    • Combobox
    • DatePicker
    • DatePickerInput
    • DateRangePicker
    • DateRangePickerInput
    • DatetimePicker
    • DatetimePickerInput
    • Dialog
    • Dropdown
    • Dropzone
    • ErrorMessage
    • FileInput
    • FlashMessages
    • FormComponent
    • Icon
    • IconButton
    • ImageGallery
    • InfoBox
    • Input
    • Label
    • Layout
    • Lightbox
    • ListItem
    • Loader
    • Lozenge
    • Menu
    • Message
    • Modal
    • ModalDialog
    • ModalHeader
    • MultiCombobox
    • MultiSelect
    • Pagination
    • Paper
    • Popover
    • Radio
    • RadioGroup
    • RasterImage
    • Select
    • Switch
    • Tabs
    • TextInput
    • TextLink
    • Textarea
    • TimePicker
    • TimePickerInput
    • Toggle
    • Tooltip
    • Typography
  • Wysiwygnpmv16.6.0

    • Overview
Previous← Smart-address overviewNextStyles overview →

@uxf/stylelint-config

npm

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.

What it checks

  • stylelint-config-recommended: unknown properties, values, at-rules, selectors and functions, duplicates, invalid media queries, deprecated properties and keywords,
  • Tailwind CSS 3: @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,
  • CSS Modules: :global is a known pseudo-class,
  • no vendor prefixes (-webkit-, -ms-…) in properties, values, selectors, at-rules and media features: autoprefixer adds the ones the browserslist needs,
  • no redundant code: shorthand values (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,
  • the order inside a rule and the empty lines around its groups (below).

no-descending-specificity and selector-type-no-unknown are off, as they were in every UXF project config.

Order inside a rule

.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");
    }
}
  1. the custom properties the rule scopes, in any order,
  2. its mixins: @apply, which UXF CSS is moving away from, and whatever mixin syntax replaces it,
  3. its own declarations, in alphabetical order (a prefixed property by its unprefixed name), which override what a mixin sets,
  4. nested rules and at-rules, in any order.

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.

Moving an @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.

What it leaves out

Of the rules stylelint-config-standard adds to the recommended set:

  • notation (rgb() instead of rgba(), 0 instead of 0px, short hex colours, quotes in url() and font names, keyword case),
  • naming patterns of classes, ids, custom properties, keyframes and layers,
  • one declaration per line, which oxfmt does.

Installation

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.

Usage

// 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"
}

Measured

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.

Not here yet

  • stylelint 18. 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.
  • Tailwind CSS 4 (@theme, @utility, @variant, @custom-variant, @source, @plugin, @reference), which no UXF project uses yet.