From 2fc67f2210afafb4d7dc7345e68dd083db32e417 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Tue, 1 May 2018 13:09:55 -0700 Subject: [PATCH] Revert "Merge pull request #4494 from tb3088/EOL-handling" This reverts commit dfe4f56c75abe1fb25f5453a5e7828a4c2504260, reversing changes made to e90c87f88524c2f4a41f4b721e3b7b0eb29eafcc. Revert changes to makefile and format checker --- Makefile | 9 +++------ scripts/gofmtcheck.sh | 14 ++++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 45f107947..0ccd547b4 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ VET?=$(shell ls -d */ | grep -v vendor | grep -v website) GITSHA:=$(shell git rev-parse HEAD) # Get the current local branch name from git (if we can, this may be blank) GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null) -GOFMT_FILES?=find . -path ./vendor -prune -o -name "*.go" +GOFMT_FILES?=$$(find . -not -path "./vendor/*" -name "*.go") GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) GOPATH=$(shell go env GOPATH) @@ -58,13 +58,10 @@ dev: deps ## Build and install a development build @cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH) fmt: ## Format Go code - @$(GOFMT_FILES) | xargs gofmt -w -s + @gofmt -w -s $(GOFMT_FILES) fmt-check: ## Check go code formatting - @echo "==> Checking that code complies with gofmt requirements..." - @echo "You can use the command: \`make fmt\` to reformat code." - @$(GOFMT_FILES) | xargs $(CURDIR)/scripts/gofmtcheck.sh - @echo "Check complete." + $(CURDIR)/scripts/gofmtcheck.sh $(GOFMT_FILES) fmt-docs: @find ./website/source/docs -name "*.md" -exec pandoc --wrap auto --columns 79 --atx-headers -s -f "markdown_github+yaml_metadata_block" -t "markdown_github+yaml_metadata_block" {} -o {} \; diff --git a/scripts/gofmtcheck.sh b/scripts/gofmtcheck.sh index cc6deb81e..5b99bcdc4 100755 --- a/scripts/gofmtcheck.sh +++ b/scripts/gofmtcheck.sh @@ -1,8 +1,14 @@ #!/usr/bin/env bash -for f in $@; do - [ -n "`dos2unix 2>/dev/null < $f | gofmt -s -d`" ] && echo $f -done +# Check gofmt +echo "==> Checking that code complies with gofmt requirements..." +gofmt_files=$(gofmt -s -l ${@}) +if [[ -n ${gofmt_files} ]]; then + echo 'gofmt needs running on the following files:' + echo "${gofmt_files}" + echo "You can use the command: \`make fmt\` to reformat code." + exit 1 +fi +echo "Check passed." -# always return success or else 'make' will abort exit 0