前端代碼風格自動化系列(五)之共同出擊

咱們在前面的四篇中介紹了huskycommitlintlint-stagedprettier這些工具,能夠完成以最小的代價在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"
    }
  }
}

這裏對於項目裏tsjsjsxless分別作了提交前格式化操做,對於提交規範作了校驗。git

相關文章
相關標籤/搜索