[英]How to enforce tslint rules before merging/push/commit git commands
I have a web app running in Azure DevOps and want to ensure the code is up to standards before merging; 我有一个在Azure DevOps中运行的Web应用程序,想要在合并之前确保代码符合标准。 for example to "dev/test/master".
例如“ dev / test / master”。 I have made a tslint rule file and would like to enforce this rule.
我已经创建了一个tslint规则文件,并希望执行此规则。 Enforce it in a way that, whenever theirs a pull request to a branch.
以这样的方式执行它,只要他们向分支发出拉请求。 When approved or before it gets approved make the build fail.
当批准或批准之前,会使构建失败。 Or even better, don't let the developer make a pull request until his code matches tslint rules.
甚至更好的是,在代码符合tslint规则之前,不要让开发人员提出拉取请求。
Is there any tool I can integrate to azure pipelines to check code and compare it with tslint rules so whenever it doesn't match, make the merge or build fail. 我是否可以集成到天蓝色的管道中以检查代码并将其与tslint规则进行比较的任何工具,以便每当不匹配时都会使合并或构建失败。
Use husky pre-commit hook. 使用沙哑的预提交钩子。
Git Hooks that work with Husky framework. 与Husky框架一起使用的Git Hooks。 git-scm.com/docs/githooks
git-scm.com/docs/githooks
Install husky and add below code in your package.json. 安装husky并在package.json中添加以下代码。 It'll not allow committing the code if tslint rule or build fails.
如果tslint规则或构建失败,则不允许提交代码。
"scripts": {
"build": "ng build --prod"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run build"
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.