咱們在前面的四篇中介紹了husky
、commitlint
、lint-staged
、prettier
這些工具,能夠完成以最小的代價在Git提交到遠程倉庫前,格式化爲統一風格的代碼,eslint你們都很熟悉這裏就不列舉了。下面舉一個配置。react
{ "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
分別作了提交前格式化操做,對於提交規範作了校驗。git