代碼風格統一:commitlint & eslint & standard-version

Commitlint 配置

  • 添加包git

    yarn add @commitlint/cli @commitlint/config-conventional husky -D
  • 配置package.jsongithub

    "husky": {
        "hooks": {
          // 此處若是不使用husky 須要將HUSKY_GIT_PARAMS 替換爲 GIT_PARAMS
          "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
        }
      },
      "commitlint": {
        "extends": [
          "@commitlint/config-conventional"
        ]
      }
  • 效果: 代碼提交的格式不符合標準 就會直接被拒絕。在團隊協做時提交歷史的回溯須要有良好的提交歷史

版本管理

yarn add standard-version -D

配置package.jsonjson

"scripts": {
    "release": "standard-version"
  }

執行 yarn release 生成CHANGELOG.md 相似bash

# Change Log

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="1.0.3"></a>
## 1.0.3 (2018-12-05)


### Features

* **lint:** 添加commitlint配置 ([faee26d](http://url/commits/faee26d))
* **lint:** 簡化commitlint配置 ([affeb7d](http://url/commits/affeb7d))

ESLint配置

yarn add lint-staged -D

配置package.jsonmarkdown

"husky": {
    "hooks": {
      // 代碼提交前 執行lint 也能夠配合prettier將代碼直接格式化後提交
      "pre-commit": "lint-staged"
    }
  },
"lint-staged": {
    "linters": {
      "/src/**/*.js": [
        "eslint --fix",
        "git add"
      ]
    },
    "ignore": [
      "/**/*.min.js"
    ]
  }

代碼提交以前執行lint 保證代碼格式統一ide

相關文章
相關標籤/搜索