node.js - 如何将 git prehook 添加到 tslint?
问题描述
如果代码有任何 linting 问题无法提交,我正在尝试添加 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 钩子lint-staged
=> 对 git 中的暂存文件运行命令(因此无需对所有文件运行 tslint)
参考:
在,package.json
指定lint-staged
和字段:pre-commit
husky
"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"
]
}
推荐阅读
- java - 如何添加旋转而不是设置它?Java3d
- node.js - 如何从段在 AWS 开发工具包中进行身份验证?
- monitoring - 组织在 grafana 中没有托管指标实例错误
- python - 如何使用 RDFLib 添加复合节点?
- visual-studio-code - vscode 缩进整行而不是插入制表符
- github - Github 分支保护规则/状态检查
- php - 为什么当我使用 Route::domain()->group() 时没有设置 cookie?
- ros - 如何将 ROS 包传递给其他人?
- javascript - Vue.js 中的条件类样式绑定
- python-3.x - 如何在条件为真之前获得 50 行的值