Merge pull request #4092 from mitchellh/gofmt

Gofmt
This commit is contained in:
Matthew Hooker 2016-11-01 14:07:41 -07:00 committed by GitHub
commit 32c0fef4c1
2 changed files with 20 additions and 2 deletions

View File

@ -4,6 +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 . -not -path "./vendor/*" -name "*.go")
default: deps generate test dev
@ -40,7 +41,10 @@ dev: deps ## Build and install a development build
@PACKER_DEV=1 GO15VENDOREXPERIMENT=1 sh -c "$(CURDIR)/scripts/build.sh"
fmt: ## Format Go code
@gofmt -s -w `go list -f {{.Dir}} ./... | grep -v "/vendor/"`
@gofmt -w -s $(GOFMT_FILES)
fmt-check: ## Check go code formatting
$(CURDIR)/scripts/gofmtcheck.sh $(GOFMT_FILES)
# Install js-beautify with npm install -g js-beautify
fmt-examples:
@ -52,7 +56,7 @@ generate: deps ## Generate dynamically generated code
go generate .
gofmt -w command/plugin.go
test: deps ## Run unit tests
test: deps fmt-check ## Run unit tests
@go test $(TEST) $(TESTARGS) -timeout=2m
@go tool vet $(VET) ; if [ $$? -eq 1 ]; then \
echo "ERROR: Vet found problems in the code."; \

14
scripts/gofmtcheck.sh Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# 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."
exit 0