【发布时间】:2021-07-14 12:11:00
【问题描述】:
我的预提交脚本有问题。我正在尝试运行我的 Angular 项目预提交文件的“ng lint”;当检测到 lint 错误但预提交过程成功通过时,我会在日志中看到错误。 我需要在预提交文件中执行 ng-lint,因为我要运行其他验证...当 ng lint 未成功通过时,我该如何获取消息?
我的脚本:
#!/bin/bash
### other scripts to validate custom commits
-----------
### Run ng lint
echo "pre-commit hook --> linting" ng lint
ng lint
echo -e "ng lint pass sucessfully \n\n"
日志
pre-commit hook --> linting
Linting "front-firefly-backoffice"...
/home/apanez/Escritorio/htdocs/eci/front-firefly/src/app/stock/limit-sale/components/limit-sale-detail/limit-sale-detail.component.ts:30:14
ERROR: 30:14 component-class-suffix The name of the class LimitSaleDetailComp should end with the suffix Component (https://angular.io/styleguide#style-02-03)
Lint errors found in the listed files.
ng lint pass sucessfully
【问题讨论】:
-
使用子shell 捕获
ng lint输出和LINTMSG="$(ng lint)"。ng lint可能会在成功完成时返回 0,而在失败时可能会返回任何其他值。然后您可以使用if [ $? != 0 ]; then { processing error from $LINTMSG }进行测试。 -
谢谢!!!是什么?在 [$? != 0 ]
-
$?设置为最后执行命令的退出代码。大多数命令(无论是否内置)都将返回 0 表示成功,而其他任何命令都表示失败。我建议您阅读 bash 手册页,特殊参数部分。 -
我会的!!对不起,我对 bash 命令了解不多,谢谢!!
-
set -e在你的 shell 脚本中会使出错的子命令出错
标签: angular bash githooks lint