我们在前面的四篇中介绍了husky
、commitlint
、lint-staged
、prettier
这些工具,可以完成以最小的代价在Git提交到远程仓库前,格式化为统一风格的代码,eslint大家都很熟悉这里就不列举了。下面举一个配置。
{
"devDependencies": {
"babel-eslint": "^10.0.1",
"eslint": "^5.4.0",
"eslint-config-airbnb": "^17.0.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-babel": "^5.1.0",
"eslint-plugin-compat": "^2.6.2",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-markdown": "^1.0.0-beta.6",
"eslint-plugin-react": "^7.11.1",
"husky": "^1.1.2",
"lint-staged": "^8.0.4",
"prettier": "1.14.3",
"stylelint": "^9.4.0",
"stylelint-config-prettier": "^4.0.0",
"stylelint-config-standard": "^18.0.0",
"tslint": "^5.10.0",
"tslint-config-prettier": "^1.10.0",
"tslint-react": "^3.6.0",
},
"lint-staged": {
"**/*.{js,jsx,less}": [
"prettier --write",
"git add"
],
"**/*.{js,jsx}": "npm run lint-staged:js",
"**/*.less": "stylelint --syntax less"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint-staged",
"commit-msg": "commitlint -e $HUSKY_GIT_PARAMS"
}
}
}
这里对于项目里ts
、js
、jsx
、less
分别做了提交前格式化操作,对于提交规范做了校验。