Commit b4c8e3c7 authored by Adam Reese's avatar Adam Reese

Merge pull request #376 from adamreese/ref/static-code-tools

ref(test-style): add a script for linting tools
parents d61ba060 ad41105f
...@@ -58,33 +58,15 @@ test-unit: ...@@ -58,33 +58,15 @@ test-unit:
@echo Running tests... @echo Running tests...
go test -v $(GO_PKGS) go test -v $(GO_PKGS)
.PHONY: .test-style
test-style: lint vet
@if [[ -z $(shell gofmt -e -l -s $(GO_DIRS) | wc -l) ]]; then \
echo "gofmt check failed:"; gofmt -e -d -s $(GO_DIRS); exit 1; \
fi
.PHONY: test-flake8 .PHONY: test-flake8
test-flake8: test-flake8:
@echo Running flake8... @echo Running flake8...
flake8 expansion flake8 expansion
@echo ---------------- @echo ----------------
.PHONY: lint .PHONY: test-style
lint: test-style:
@echo Running golint... @scripts/validate-go.sh
@for i in $(GO_PKGS); do \
golint $$i; \
done
@echo -----------------
.PHONY: vet
vet:
@echo Running go vet...
@for i in $(GO_DIRS); do \
go tool vet $$i; \
done
@echo -----------------
HAS_GLIDE := $(shell command -v glide;) HAS_GLIDE := $(shell command -v glide;)
HAS_GOLINT := $(shell command -v golint;) HAS_GOLINT := $(shell command -v golint;)
......
...@@ -12,7 +12,7 @@ dependencies: ...@@ -12,7 +12,7 @@ dependencies:
- cd $GOPATH - cd $GOPATH
- mkdir -p $GOPATH/src/$IMPORT_PATH - mkdir -p $GOPATH/src/$IMPORT_PATH
- cd $HOME/deployment-manager - cd $HOME/deployment-manager
- rsync -azC --delete ./ "$GOPATH/src/$IMPORT_PATH/" - rsync -az --delete ./ "$GOPATH/src/$IMPORT_PATH/"
- wget "https://github.com/Masterminds/glide/releases/download/$GLIDE_VERSION/glide-$GLIDE_VERSION-linux-amd64.tar.gz" - wget "https://github.com/Masterminds/glide/releases/download/$GLIDE_VERSION/glide-$GLIDE_VERSION-linux-amd64.tar.gz"
- mkdir -p $HOME/bin - mkdir -p $HOME/bin
- tar -vxz -C $HOME/bin --strip=1 -f glide-$GLIDE_VERSION-linux-amd64.tar.gz - tar -vxz -C $HOME/bin --strip=1 -f glide-$GLIDE_VERSION-linux-amd64.tar.gz
......
#!/usr/bin/env bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eo pipefail
[[ "$TRACE" ]] && set -x
readonly reset=$(tput sgr0)
readonly red=$(tput bold; tput setaf 1)
readonly green=$(tput bold; tput setaf 2)
readonly yellow=$(tput bold; tput setaf 3)
exit_code=0
find_go_files() {
git ls-files '*.go'
}
echo "==> Running golint..."
for pkg in $(glide nv); do
if golint_out=$(golint "$pkg" 2>&1); then
echo "${yellow}${golint_out}${reset}"
fi
done
echo "==> Running go vet..."
if ! vet_out=$(go vet "$(glide nv)" 2>&1); then
echo
echo "${red}${vet_out}${reset}"
exit_code=1
fi
echo "==> Running gofmt..."
failed_fmt=$(find_go_files | xargs gofmt -s -l)
if [[ -n "${failed_fmt}" ]]; then
echo "${red}"
echo "gofmt check failed:"
echo "$failed_fmt"
echo "${reset}"
exit_code=1
fi
exit ${exit_code}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment