代码风格统一:commitlint & eslint & standard-version
Commitlint 配置
添加包
yarn add @commitlint/cli @commitlint/config-conventional husky -D
配置
package.json
"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.json
"scripts": { "release": "standard-version" }
执行 yarn release
生成CHANGELOG.md 类似
# 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.json
"husky": { "hooks": { // 代码提交前 执行lint 也可以配合prettier将代码直接格式化后提交 "pre-commit": "lint-staged" } }, "lint-staged": { "linters": { "/src/**/*.js": [ "eslint --fix", "git add" ] }, "ignore": [ "/**/*.min.js" ] }
代码提交之前执行lint 保证代码格式统一
相关推荐
FavoriteStudent 2018-08-20
zhglinux 2020-07-17
Dimples 2020-06-07
tianzyc 2020-01-24
James0 2019-12-15
qiupu 2019-11-08
meylovezn 2019-10-25
terabits的钵壳 2012-03-24
微麦PHP 2019-07-01
wenjiusui0 2019-07-01
shiningchen 2019-06-30
shiningchen 2019-06-30
WKYCSDN 2019-06-30
pythonxuexi 2019-06-30
hualala 2019-06-28
hualala 2019-06-27
sundehui0 2019-06-21
GATSBYER 2007-11-07