英文:
Check format for Continous integration
问题
我正在尝试编写一个Makefile命令,如果Go代码格式不正确,将输出一个错误。这是为了CI步骤。我在如何在Makefile中使其工作方面遇到了困难。这个解决方案在bash命令行上可以工作:
! gofmt -l . 2>&1 | read
但是将其复制到Makefile中:
ci-format:
@echo "$(OK_COLOR)==> Checking formatting$(NO_COLOR)"
@go fmt ./...
@! gofmt -l . 2>&1 | read
我得到以下错误:
/bin/sh: 1: read: arg count
英文:
I am trying to write a Makefile command that will output an error if the Go code is not correctly formatted. This is for a CI step. I am struggling with how to get it working in the make file. This solution works on the bash command line:
! gofmt -l . 2>&1 | read
But copying this into the Makefile:
ci-format:
@echo "$(OK_COLOR)==> Checking formatting$(NO_COLOR)"
@go fmt ./...
@! gofmt -l . 2>&1 | read
I get the following error:
/bin/sh: 1: read: arg count
答案1
得分: 15
这些天,我使用golangci-lint,其中包括gofmt
检查作为一个选项。
但是,如果出于某种原因你想自己做这个,我之前用于这个目的的命令是:
diff -u <(echo -n) <(gofmt -d ./)
例如,你可以查看我项目中的.travis.yml文件。
英文:
These days, I use golangci-lint, which includes gofmt
checking as an option.
But if for some reason you want to do this yourself, the command I previously used for precisely that purpose is:
diff -u <(echo -n) <(gofmt -d ./)
See, for example, the .travis.yml files on one of my projects.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论