配置 husky,lint-staged
安装以下软件包以在提交前运行预提交挂钩
npm install -D eslint prettier stylelint
"devDependencies": {
"eslint": "^7.32.0",
"prettier": "^2.3.2",
"stylelint": "^13.13.1"
}
此命令将为以下安装的软件包安装和配置 husky 和 lint-staged
npx mrm@2 lint-staged
"lint-staged": {
"*.js": "eslint --cache --fix",
"*.css": "stylelint --fix",
"*.{js,css,md}": "prettier --write"
}
"devDependencies": {
...
"husky": ">=6",
"lint-staged": ">=10",
...
}
"scripts": {
...
"prepare": "husky install"
},
配置文件
- Stylelint 配置文件 -> .stylelintrc
{
"plugins": [
<CAN_HAVE_PLUGINS> LIKE ("stylelint-order","stylelint-scss") AND FOLLOWING PROPERTIES OVERRIDDEN IN "rules {...}"
],
"rules": {
"indentation": 2,
"unit-allowed-list": [
"em",
"rem",
"px",
"%"
],
"order/properties-order": [
[
"width",
"height"
],
"order/properties-alphabetical-order": null,
"unit-case": "lower",
"property-case": "lower",
"string-quotes": "single"
}
}
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"tabWidth": 4,
"useTabs": true,
"semi": false
}
- Eslint 配置文件 -> “eslintrc.json”
{
"extends": ["eslint:recommended"],
"parser": "babel-eslint",
"plugins": [
<PLUGINS>
],
"rules": {
...
"no-delete-var": "error",
"no-dupe-args": "error",
"no-dupe-class-members": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
...
<MORE_RULES_DEFINED>
},
"env": {
"es2021": true,
"node": true
},
}
- 您也可以忽略文件以从 linting 中忽略以下文件/目录
- .prettierignore
- .stylelintignore
- .eslintignore