You will need stylelint 15.0.0 or higher as a devDependency.
pnpm add -D stylelint @bernankez/stylelint-config{
"extends": "@bernankez/stylelint-config"
}Note: It seems that the
ignoreFilesin my stylelint-config is not having effect. You may add.stylelintignoremanually.
For example:
{
"scripts": {
"stylelint": "stylelint **/**/*.css",
"stylelint:fix": "stylelint **/**/*.css --fix"
}
}To lint other file types, you need to add the file types manually to apply Stylelint. For example:
{
"scripts": {
"stylelint": "stylelint **/**/*.{css,vue}",
"stylelint:fix": "stylelint **/**/*.{css,vue} --fix"
}
}Install VS Code Stylelint extension and create .vscode/settings.json or add it to your global settings
{
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": true
},
// disable VS Code's built-in linters is optional
"css.validate": false,
"scss.validate": false,
"less.validate": false,
// add extensions you would like to lint on save
"stylelint.validate": [
"css",
"postcss",
"vue",
"html"
]
}Set your .stylelintrc.json to:
{
"extends": "@bernankez/stylelint-config/scss"
}If you want to apply lint and auto-fix before every commit, you can add the following to your package.json:
{
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*.{css,scss,less,vue}": "stylelint --fix",
// if you are using ESLint also.
"*": "eslint --fix"
}
}and then
pnpm add -D lint-staged simple-git-hooksIt's recommended to use Stylelint with ESLint. Here's my eslint-config.