husky,防止格式有害代码上传工具及新版本变动

源自 https://www.npmjs.com/package/husky#upgrading-from-014

husky,防止格式有害代码上传工具及新版本变动

husky,防止格式有害代码上传工具

husky,主要目的是在commit, push, merge等 前/后对文本进行格式筛查(其实就是创建了一些shell 在你push commit前执行脚本进行eslint,就怕你还没在自己环境上run起来就push的东西),原理听起来很简单,但是他给你写了一堆脚本就不简单了。因为你自己创建这一堆脚本很费劲。。。清奇的思路。
对于husky能监听的hooks先对项目进行git init,如果在git init前安装husky会导致.hook安装失败,请npm uninstall husky再init再安装。。
hooks:

  1. applypatch-msg
  2. post-applypatch
  3. post-rewrite
  4. pre-commit
  5. pre-rebase
  6. commit-msg
  7. post-checkout
  8. post-update
  9. pre-merge-commit
  10. pre-push
  11. etc…

pre 为执行前,post为执行后,分别执行对应的命令。

新版本变动

对于0.x.x版本的husky,执行方式为在package.json内

script: {
	"precommit": "npm xxxx" // 这是你要写的规则
	
	"lint": "eslint --ext .js --ext .jsx --ext .vue client/",//这是我的代码
	"precommit": "npm run lint --fix" 		
}

对于1.x.x之后的改变是规则不在写在里面了,这也是我看了npm官网查到的,我说怎么老不执行
新版本变动:

	"script": {
		xxxxxxx
	},
	"husky": {
		"hooks": {
			"pre-commit": "npm run lint --fix",
      		"pre-push": "npm run lint --fix"
      		// 如果你想的话 加上pre-merge post-merge 等等 具体在.git/hooks
		}
	}
	

你可能感兴趣的:(前端)