[英]How to add git prehook to tslint?
我正在嘗試添加prehook,如果代碼無法提交任何棉絨問題。什么是實現它的正確方法。
tslint.sh
#!/bin/sh
sh ./npm-install.sh
if [ $? -ne 0 ]; then
echo "npm-install error, exiting.."
exit 1
fi
echo "Running ts lint"
npm run lint
if [ $? -ne 0 ]; then
echo "Unit tests error, exiting.."
exit 1
fi
我在以下方面具有成功的實施經驗:
husky
=>指定git hook lint-staged
=>運行命令以在git中暫存文件(因此無需對所有文件運行tslint) 參考:
在package.json
,在husky
字段中指定lint-staged
和pre-commit
:
"dependencies": ...,
"devDependencies": ...,
"scripts" ...,
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.ts": [ // target to all typescript files in staged stage in git
"npm run lint", // your lint command
"git add"
]
}
這是一種方法: https : //www.npmjs.com/package/pre-commit
pre-commit是git的預提交鈎子安裝程序。 在提交更改之前,它將確保您的npm測試(或其他指定的腳本)通過。 所有這些都可以在package.json中方便地配置。
package.json:
{
"name": "app name",
"version": "0.1.0",
"license": "MIT",
"author": "author",
"contributors": [
],
"description": "...",
"scripts": {
"ng": "ng",
"precommit": "lint-staged"
},
...,
"lint-staged": {
"*.{ts,js,sccs,json}": [
"ng lint app-name --fix",
"./node_modules/.bin/prettier --write",
"git add"
]
},
"dependencies": {
...
},
"devDependencies": {
...
"lint-staged": "^7.2.0",
"prettier": "^1.13.5",
"ts-node": "^6.1.2",
"tslint": "^5.10.0",
"typescript": "2.7.2"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.