Stylelint config with standard rules and useful plugins
- plugins
- Config Extended
- postcss-scss
yarn add -D postcss^8.4.27 stylelint^15.10.2 @frontendfixer/stylelint-config-standard
Create a Stylelint config file with .stylelintrc
or .stylelintrc.json
and put this lint
{
"extends": "@frontendfixer/stylelint-config-standard"
}
or you can also put it in your package.json
above scripts or higher position
"stylelint": {
"extends": "@frontendfixer/stylelint-config-standard"
}
You can add two scripts to your package.json to lint and/or fix:
"scripts": {
"lint": "stylelint '**/*.{css,scss}'",
"lint:fix": "stylelint '**/*.{css,scss}' --fix",
},
- Now you can manually lint your code by running
yarn run lint
and fix all fixable issues withyarn run lint:fix
. You probably want your editor to do this though.
You should read this entire thing. Serious!
Once you have done one, or both, of the above installs. You probably want your editor to lint and fix for you. Here are the instructions for VS Code:
- Install the vscode-stylelint
- Now we need to setup some VS Code settings via
Code/File
→Preferences
→Settings
. It's easier to enter these settings while editing thesettings.json
file, so click the Open (Open Settings) icon in the top right corner:
// disable the built-in CSS, Less, and SCSS linters:
"css.validate": false,
"scss.validate": false,
// enable stylelint
"stylelint.validate": ["css", "scss"],
// tell the Stylelint plugin to run on save
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": true
},