- css, sass, scss, Vue out-of-box
- Single quotes
- Also lint for acss, wxss (
css of mini-program
) - Auto fix for formatting
- Only one-line of config
pnpm add -D stylelint @leedomjs/stylelint-config
{
"extends": "@leedomjs/stylelint-config"
}
For example:
{
"scripts": {
"lint:style": "stylelint **/*.{css,scss,sass,acss,wxss,vue}",
"lint:style-fix": "stylelint **/*.{css,scss,sass,acss,wxss,vue} --fix"
}
}
Install VS Code Stylelint extension
Add the following settings to your settings.json
:
If you want to apply lint and auto-fix before every commit, you could do this:
1. husky + lint-staged
pnpm dlx husky-init && pnpm install -D husky lint-staged
and add the following to your package.json
:
{
"scripts": {
// This script will be added automatically when husky is installed successfully.
"prepare": "husky install"
},
"lint-staged": {
"**/*.{css,scss,sass,acss,wxss,vue}": "stylelint --fix"
}
}
then add the following to your pre-commit
:
.husky/pre-commit
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# remove the default script
# npx test
# add this script
npx lint-staged
If your project is small-sized, and you need quickly set up hooks and forget about it, simple-git-hook
will be a good choice.
pnpm install -D simple-git-hooks lint-staged
and add the following to your package.json
:
{
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"lint-staged": {
"**/*.{css,scss,sass,acss,wxss,vue}": "stylelint --fix"
}
}
then run the CLI script to update the git hooks with the commands from the config:
# [Optional] These 2 steps can be skipped for non-husky users
git config core.hooksPath .git/hooks/
rm -rf .git/hooks
# Update ./git/hooks
npx simple-git-hooks
You can override the rules in your .stylelintrc
file.
{
"extends": "@leedomjs/stylelint-config",
"rules": {
// your rules...
}
}