Squashed 'tools/' changes from ec369f58d..f041a74ff

f041a74ff Undo some quoting that broke the test script (#160)
b1c21a068 Merge pull request #158 from weaveworks/go-1-13
d5c7dd0cd Run shell-lint during CI, and fix warnings
6db1abd14 Update to Go 1.13.1
d6cc704a2 Fix comment
7139116ae Revert "Push comments to the left so they don't appear in scripts"
e47e58f7b Push comments to the left so they don't appear in scripts
3945fcec8 Remove nonexistent env var GIT_TAG
cd6299284 Merge pull request #156 from weaveworks/drop-quay
af0eb5119 Merge pull request #157 from weaveworks/fix-image-tag-prefix-length
0b9aee4f2 Fix image-tag object name prefix length to 8 chars.
813c28fe7 Move from CircleCI 1.0 to 2.0
425cf4ef1 Move from quay.io to Dockerhub
87ccf4fd1 Merge pull request #155 from weaveworks/go-1-12
c31bc2865 Update lint script to work with Go 1.12
ed8e380d7 Update to Go 1.12.1

git-subtree-dir: tools
git-subtree-split: f041a74ffbf273b627d6c960f17357108d0dbd1c
This commit is contained in:
Bryan Boreham
2019-10-02 14:34:20 +00:00
parent 5e3c8ab358
commit a0d60e4de9
10 changed files with 72 additions and 70 deletions

41
lint
View File

@@ -22,7 +22,6 @@ LINT_IGNORE_FILE=${LINT_IGNORE_FILE:-".lintignore"}
IGNORE_LINT_COMMENT=
IGNORE_SPELLINGS=
PARALLEL=
while true; do
case "$1" in
-nocomment)
@@ -37,10 +36,6 @@ while true; do
IGNORE_SPELLINGS="$2,$IGNORE_SPELLINGS"
shift 2
;;
-p)
PARALLEL=1
shift 1
;;
*)
break
;;
@@ -65,6 +60,7 @@ spell_check() {
}
lint_go() {
# This function is called on a whole directory containing Go files
local filename="$1"
local lint_result=0
@@ -73,7 +69,7 @@ lint_go() {
echo "${filename}: run gofmt -s -w ${filename}"
fi
go tool vet "${filename}" || lint_result=$?
go vet "${filename}" || lint_result=$?
# golint is completely optional. If you don't like it
# don't have it installed.
@@ -185,7 +181,7 @@ lint() {
case "$mimetype.$ext" in
text/x-shellscript.*) lint_sh "${filename}" || lint_result=1 ;;
*.go) lint_go "${filename}" || lint_result=1 ;;
*.go) ;; # done at directory level
*.tf) lint_tf "${filename}" || lint_result=1 ;;
*.md) lint_md "${filename}" || lint_result=1 ;;
*.py) lint_py "${filename}" || lint_result=1 ;;
@@ -208,7 +204,7 @@ lint_files() {
while read -r filename; do
lint "${filename}" || lint_result=1
done
exit $lint_result
return $lint_result
}
matches_any() {
@@ -239,18 +235,33 @@ filter_out() {
fi
}
list_files() {
lint_directory() {
local dirname="$1"
local lint_result=0
# This test is just checking if there are any Go files in the directory
if compgen -G "$dirname/*.go" >/dev/null; then
lint_go "${dirname}" || lint_result=1
fi
find . -maxdepth 1 "$dirname" | filter_out "$LINT_IGNORE_FILE" | lint_files
return $lint_result
}
lint_directories() {
local lint_result=0
while read -r dirname; do
lint_directory "${dirname}" || lint_result=1
done
exit $lint_result
}
list_directories() {
if [ $# -gt 0 ]; then
find "$@" \( -name vendor -o -name .git \) -prune -o -type f
else
git ls-files --exclude-standard | grep -vE '(^|/)vendor/'
find "$@" \( -name vendor -o -name .git -o -name .cache -o -name .pkg \) -prune -o -type d
fi
}
if [ $# = 1 ] && [ -f "$1" ]; then
lint "$1"
elif [ -n "$PARALLEL" ]; then
list_files "$@" | filter_out "$LINT_IGNORE_FILE" | xargs -n1 -P16 "$0"
else
list_files "$@" | filter_out "$LINT_IGNORE_FILE" | lint_files
list_directories "$@" | lint_directories
fi