Skip to content

Repository files navigation

@wagtail/stylelint-config-wagtail on npm

Shareable stylelint config for CSS and SCSS, following Wagtail’s code style.

Usage

Install stylelint, and the config:

npm install --save-dev stylelint @wagtail/stylelint-config-wagtail

Then configure stylelint to use this config. As a stylelint.config.js or stylelint.config.mjs in the root of your project:

/** @type {import('stylelint').Config} */
export default {
  // See https://github.com/wagtail/stylelint-config-wagtail for rules.
  extends: '@wagtail/stylelint-config-wagtail',
};

Tips

Linting setup for ongoing projects

Review our CHANGELOG for guidance on how to upgrade a project’s linting to a specific version.

More generally, when retrofitting stricter linting onto an existing project, consider a gradual approach to linting strictness, so you can start using linting without having to change significant portions of the project’s code. Here is an example, disabling commonly hard-to-retrofit rules:

// Rules which we ideally would want to enforce but are reporting too many issues currently.
const legacyRules = {
  'max-nesting-depth': null,
  'selector-max-specificity': null,
};

/** @type {import('stylelint').Config} */
export default {
  // See https://github.com/wagtail/stylelint-config-wagtail for rules.
  extends: '@wagtail/stylelint-config-wagtail',
  rules: {
    ...legacyRules,
  },
};

Agent skills

This project ships two agent skills for AI coding agents:

  • upgrading-stylelint — for auditing or carrying out a Stylelint upgrade within a project, including checking the upgrade path, reviewing migration guides, updating dependencies or config, running QA, and reporting follow-up work.
  • upgrading-shared-stylelint-config — for upgrading this shared Stylelint configuration itself to a new major release, including updating version constraints, reconfiguring rules, and releasing.

Install the project skills with Vercel Lab’s Agent Skills:

npx skills add wagtail/stylelint-config-wagtail

Example prompt:

Use the upgrading-stylelint skill to upgrade this project from Stylelint 16 to 17, including updating to the compatible stylelint-config-wagtail version. Update dependencies and config as needed, update as much of the styles as you can if safe.

Common CLI flags

We recommend the following run script to add to your package.json:

"lint:css": "stylelint --report-needless-disables --report-unscoped-disables 'src/sass'"
  • Use --report-needless-disables to ensure you do not use more stylelint-disable comments than needed.
  • Use --report-unscoped-disables to prevent fully disabling linting.
  • Target specific folders so Stylelint doesn’t attempt to lint other file types, say JS or HTML files.

.stylelintignore

Stylelint supports ignore patterns in a .stylelintignore file, however we tend not to use this since we lint all files within a given folder.

Prettier

This config is Prettier-compatible, there isn’t anything extra needed.

Tailwind

This config should work with Tailwind with no adjustments needed. Please submit an issue if that’s not the case.

prek for pre-commit hooks

We recommend prek, an implementation of the pre-commit framework to manage hooks. Our sample setup uses a standard .pre-commit-config.yaml, so the same configuration also works with pre-commit if needed:

default_language_version:
  node: system
repos:
  - repo: https://github.com/thibaudcolas/pre-commit-stylelint
    rev: v17.9.0
    hooks:
      - id: stylelint
        files: \.(css|scss)$
        additional_dependencies:
          - stylelint@17.9.0
          - '@wagtail/stylelint-config-wagtail@2.0.0'

Related tools

To get the most out of this config, it is assumed that projects have the following tools set up:

What’s included

See config.js for the config definition. This package includes configuration from:

Rules

Rule Config
at-rule-no-deprecated Enabled
block-no-empty Enabled
color-hex-length "short"
color-named "never"
color-no-invalid-hex Enabled
comment-no-empty Enabled
custom-property-no-missing-var-function Enabled
declaration-block-no-duplicate-custom-properties Enabled
declaration-block-no-duplicate-properties Enabled
declaration-block-no-redundant-longhand-properties Enabled
declaration-block-no-shorthand-property-overrides Enabled
declaration-block-single-line-max-declarations 1
declaration-no-important Enabled
declaration-property-value-allowed-list Enabled - see Config
declaration-property-value-disallowed-list {"/^border/":["none"]}, {"severity":"error"}
declaration-property-value-keyword-no-deprecated Enabled
font-family-no-duplicate-names Enabled
font-family-no-missing-generic-family-keyword Enabled
function-calc-no-unspaced-operator Enabled
function-linear-gradient-no-nonstandard-direction Enabled
function-url-quotes "always"
keyframe-block-no-duplicate-selectors Enabled
keyframe-declaration-no-important Enabled
length-zero-no-unit Enabled
max-nesting-depth 3
media-feature-name-no-unknown Enabled
media-type-no-deprecated Enabled
named-grid-areas-no-invalid Enabled
nesting-selector-no-missing-scoping-root {"ignoreAtRules":["mixin"]}
no-duplicate-at-import-rules Enabled
no-empty-source Enabled
no-invalid-double-slash-comments Enabled
no-invalid-position-at-import-rule {"ignoreAtRules":["use","forward"]}
no-invalid-position-declaration Enabled
no-irregular-whitespace Enabled
order/order [{"name":"include","type":"at-rule"},"declarations"]
property-disallowed-list ["/forced-color-adjust/","/left/","/right/","text-transform"]
property-no-deprecated Enabled
property-no-unknown Enabled
property-no-vendor-prefix Enabled
rule-empty-line-before "always", {"except":["after-single-line-comment","first-nested"]}
scale-unlimited/declaration-strict-value Enabled - see Config
scss/at-extend-no-missing-placeholder Enabled
scss/at-if-no-null Enabled
scss/at-rule-no-unknown Enabled
scss/comment-no-empty Enabled
scss/declaration-nested-properties-no-divided-groups Enabled
scss/dollar-variable-no-missing-interpolation Enabled
scss/function-quote-no-quoted-strings-inside Enabled
scss/function-unquote-no-unquoted-strings-inside Enabled
scss/load-no-partial-leading-underscore Enabled
scss/load-partial-extension "never"
scss/media-feature-value-dollar-variable "always", {"ignore":["keywords"]}
scss/no-duplicate-mixins Enabled
scss/no-global-function-names Enabled
scss/selector-class-pattern {}, {"resolveNestedSelectors":true}
scss/selector-no-redundant-nesting-selector Enabled
scss/selector-no-union-class-name Enabled
selector-anb-no-unmatchable Enabled
selector-attribute-name-disallowed-list "/^data-/"
selector-max-combinators 3
selector-max-id 0
selector-max-specificity "0,3,3"
selector-no-qualifying-type {"ignore":["attribute","class"]}
selector-pseudo-class-no-unknown Enabled
selector-pseudo-element-no-unknown Enabled
selector-type-no-unknown Enabled
string-no-newline Enabled
syntax-string-no-invalid Enabled
unit-no-unknown Enabled
value-no-vendor-prefix Enabled

About

Shareable stylelint config for CSS and SCSS, following Wagtail’s code style.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

11 stars

Watchers

18 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages