Skip to content

StyleLint

See the official documentation.

Terminal window
npm i -D stylelint
Terminal window
npm i -D stylelint-a11y stylelint-config-standard stylelint-order stylelint-plugin-defensive-css stylelint-use-logical-spec

These are basic .stylelintrc.json settings.

.stylelintrc.json
{
"$schema": "https://json.schemastore.org/stylelintrc.json",
"extends": ["stylelint-config-standard"],
"plugins": [
"stylelint-order",
"stylelint-use-logical-spec",
"stylelint-plugin-defensive-css"
],
"rules": {
"color-no-hex": true,
"liberty/use-logical-spec": true,
"plugin/use-defensive-css": [
true,
{
"accidental-hover": true,
"background-repeat": true,
"custom-property-fallbacks": true,
"scroll-chaining": true
}
]
},
"reportNeedlessDisables": true,
"reportInvalidScopeDisables": true
}

Create an ignore file (.stylelintignore) with the following:

build
dist
coverage
analysis

and here is a script to run stlintlint on your project:

Terminal window
# File: package.json
"style:lint": "pnpm run stylelint --cache './src/**/*.css'",
"style:lint:fix": "pnpm run style:lint --fix",