VisionApps' collection of shareable configs for Stylelint:
- extends stylelint-config-standard with rules to encourage low specificity and avoid nesting,
- includes additional configs for checking order, SCSS and CSS Modules.
Install Stylelint and this config:
$ npm install --save-dev stylelint @visionappscz/stylelint-config
Apply the config in your Stylelint config:
{
"extends": "@visionappscz/stylelint-config"
}
👉 To see the rules that this config uses, please read the main config itself.
To further extend control over coding style of your stylesheets, you can also check for properties order:
{
"extends": [
"@visionappscz/stylelint-config",
"@visionappscz/stylelint-config/order"
]
}
The order
config enforces a consistent order of content in your declaration blocks:
- Sass variables,
- CSS custom properties,
- Sass
@extend
, - single-line Sass
@include
, - declarations,
- nested rules.
For better flexibility, block at-rules (like @media
, @supports
, and also Sass @if
, @each
, etc.) can be placed
anywhere in the declaration block.
Furthermore, properties in the declarations must be ordered by following categories:
all
properties,content
,- position,
appearance
,- box model,
- typography,
- decorations,
- effects and transforms,
- interactions,
- transitions and animations.
👉 To see the order of individual properties this config prescribes, please read
the order
config itself.
👉 order
config is entirely independent on the main config and thus can be
listed anywhere in the extends
section of your config. However, that's not the
case with our other extending configs.
To lint SCSS files (i.e. *.scss
, not *.sass
), add the scss
config that
extends stylelint-config-standard-scss, fixes its incompatibilities with our
main config, and overrides some rules to better work with complex stylesheets:
{
"extends": [
"@visionappscz/stylelint-config",
"@visionappscz/stylelint-config/scss"
]
}
scss
config must come
after the main config.
👉 To see the rules that this config uses, please read the
scss
config itself.
To lint CSS files in project that leverages CSS Modules, drop in the
cssModules
config that fixes key incompatibilities of CSS Modules syntax with
the main config:
{
"extends": [
"@visionappscz/stylelint-config",
"@visionappscz/stylelint-config/cssModules"
]
}
Or along with SCSS:
{
"extends": [
"@visionappscz/stylelint-config",
"@visionappscz/stylelint-config/scss",
"@visionappscz/stylelint-config/cssModules"
]
}
cssModules
must come
after the main config, or after the scss
config, if present.
:global
pseudo selectors
are covered. All other features of CSS Modules (like composes
, :local
,
@value
, etc.) are considered non-essential as they can be implemented with
Sass (which we encourage) and thus are not recognized by this config.
👉 To see the rules that this config uses, please read the
cssModules
config itself.
ℹ️ There is a popular stylelint-config-css-modules config that recognizes all features of CSS Modules.
Stylistic rules (like indentation etc.) were dropped
in Stylelint v16. If you need to enforce them, you can use
@stylistic/stylelint-config
:
{
"extends": [
"@visionappscz/stylelint-config",
"@stylistic/stylelint-config"
]
}
Or, if you feel brave enough and don't need granular configuration of the stylistic rules, you can use Prettier.
Example of all configs combined:
{
"extends": [
"@visionappscz/stylelint-config",
"@visionappscz/stylelint-config/order",
"@visionappscz/stylelint-config/scss",
"@visionappscz/stylelint-config/cssModules",
"@stylistic/stylelint-config"
]
}
How do I change the indentation?
If using the @stylistic
plugin, just override the @stylistic/indentation
rule in your Stylelint config:
{
"extends": [
"@visionappscz/stylelint-config",
"@stylistic/stylelint-config"
],
"rules": {
"@stylistic/indentation": 2
}
}
👉 See the @stylistic/stylelint-config
documentation for more options.
If using Prettier, you can configure the indentation in your Prettier config:
{
"tabWidth": 2
}
Or in your .editorconfig
:
[*]
indent_size = 2
👉 See Prettier documentation for more options.