mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-16 03:49:52 +00:00
b990f48 Merge pull request #42 from kinvolk/lorenzo/fix-git-diff 224a145 Check if SHA1 exists before calling `git diff` 1c3000d Add auto_apply config for wcloud 0ebf5c0 Fix wcloud -serivice4fe078aMerge pull request #39 from weaveworks/fix-wrong-subtree-use3f4934dRemove generate_latest_map48beb60Sync changes done directly in scope/tools45dcdd5Merge pull request #37 from weaveworks/fix-mflag-missingb895344Use mflag package from weaveworks fork until we find a better solutione030008Merge pull request #36 from weaveworks/wcloud-service-flags9cbab40Add wcloud Makefileef55901Review feedback, and build wcloud in circle.3fe92f5Add wcloud deploy --service flag3527b56Merge pull request #34 from weaveworks/repo-branch92cd0b8[wcloud] Add support for repo_branch option9f760abAllow wcloud users to override username38037f8Merge pull request #33 from weaveworks/wcloud-templates7acfbd7Propagate the local usernamee6876d1Add template fields to wcloud config.f1bb537Merge pull request #30 from weaveworks/mike/shell-lint/dont-error-if-emptye60f5dfMerge pull request #31 from weaveworks/mike/fix-shell-lint-errorse8e2b69integrations: Fix a shellcheck linter errora781575shell-lint: Don't fail if no shell scripts founddb5efc0Merge pull request #28 from weaveworks/mike/add-image-tag5312c40Import image-tag script into build tools so it can be shared7e850f8Fix logs pathdda9785Update deploy apif2f4e5bFix the wcloud client3925eb6Merge pull request #27 from weaveworks/wcloud-events77355b9Lintd9a1c6cAdd wcloud events, update flags and error nicely when there is no config git-subtree-dir: tools git-subtree-split: b990f488bdc7909b62d9245bc4b4caf58f5ae7ea
176 lines
3.7 KiB
Bash
Executable File
176 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# This scipt lints go files for common errors.
|
|
#
|
|
# It runs gofmt and go vet, and optionally golint and
|
|
# gocyclo, if they are installed.
|
|
#
|
|
# With no arguments, it lints the current files staged
|
|
# for git commit. Or you can pass it explicit filenames
|
|
# (or directories) and it will lint them.
|
|
#
|
|
# To use this script automatically, run:
|
|
# ln -s ../../bin/lint .git/hooks/pre-commit
|
|
|
|
set -e
|
|
|
|
IGNORE_LINT_COMMENT=
|
|
IGNORE_TEST_PACKAGES=
|
|
IGNORE_SPELLINGS=
|
|
while true; do
|
|
case "$1" in
|
|
-nocomment)
|
|
IGNORE_LINT_COMMENT=1
|
|
shift 1
|
|
;;
|
|
-notestpackage)
|
|
IGNORE_TEST_PACKAGES=1
|
|
shift 1
|
|
;;
|
|
-ignorespelling)
|
|
IGNORE_SPELLINGS="$2,$IGNORE_SPELLINGS"
|
|
shift 2
|
|
;;
|
|
*)
|
|
break
|
|
esac
|
|
done
|
|
|
|
|
|
function spell_check {
|
|
filename="$1"
|
|
local lint_result=0
|
|
|
|
# we don't want to spell check tar balls, binaries, Makefile and json files
|
|
if file "$filename" | grep executable >/dev/null 2>&1; then
|
|
return $lint_result
|
|
fi
|
|
if [[ $filename == *".tar" || $filename == *".gz" || $filename == *".json" || $(basename "$filename") == "Makefile" ]]; then
|
|
return $lint_result
|
|
fi
|
|
|
|
# misspell is completely optional. If you don't like it
|
|
# don't have it installed.
|
|
if ! type misspell >/dev/null 2>&1; then
|
|
return $lint_result
|
|
fi
|
|
|
|
if ! misspell -error -i "$IGNORE_SPELLINGS" "${filename}"; then
|
|
lint_result=1
|
|
fi
|
|
|
|
return $lint_result
|
|
}
|
|
|
|
function test_mismatch {
|
|
filename="$1"
|
|
package=$(grep '^package ' "$filename" | awk '{print $2}')
|
|
local lint_result=0
|
|
|
|
if [[ $package == "main" ]]; then
|
|
return # in package main, all bets are off
|
|
fi
|
|
|
|
if [[ $filename == *"_internal_test.go" ]]; then
|
|
if [[ $package == *"_test" ]]; then
|
|
lint_result=1
|
|
echo "${filename}: should not be part of a _test package"
|
|
fi
|
|
else
|
|
if [[ ! $package == *"_test" ]]; then
|
|
lint_result=1
|
|
echo "${filename}: should be part of a _test package"
|
|
fi
|
|
fi
|
|
|
|
return $lint_result
|
|
}
|
|
|
|
function lint_go {
|
|
filename="$1"
|
|
local lint_result=0
|
|
|
|
if [ -n "$(gofmt -s -l "${filename}")" ]; then
|
|
lint_result=1
|
|
echo "${filename}: run gofmt -s -w ${filename}!"
|
|
fi
|
|
|
|
go tool vet "${filename}" || lint_result=$?
|
|
|
|
# golint is completely optional. If you don't like it
|
|
# don't have it installed.
|
|
if type golint >/dev/null 2>&1; then
|
|
# golint doesn't set an exit code it seems
|
|
if [ -z "$IGNORE_LINT_COMMENT" ]; then
|
|
lintoutput=$(golint "${filename}")
|
|
else
|
|
lintoutput=$(golint "${filename}" | grep -vE 'comment|dot imports|ALL_CAPS')
|
|
fi
|
|
if [ -n "$lintoutput" ]; then
|
|
lint_result=1
|
|
echo "$lintoutput"
|
|
fi
|
|
fi
|
|
|
|
# gocyclo is completely optional. If you don't like it
|
|
# don't have it installed. Also never blocks a commit,
|
|
# it just warns.
|
|
if type gocyclo >/dev/null 2>&1; then
|
|
gocyclo -over 25 "${filename}" | while read -r line; do
|
|
echo "${filename}": higher than 25 cyclomatic complexity - "${line}"
|
|
done
|
|
fi
|
|
|
|
return $lint_result
|
|
}
|
|
|
|
function lint {
|
|
filename="$1"
|
|
ext="${filename##*\.}"
|
|
local lint_result=0
|
|
|
|
# Don't lint deleted files
|
|
if [ ! -f "$filename" ]; then
|
|
return
|
|
fi
|
|
|
|
# Don't lint this script or static.go
|
|
case "$(basename "${filename}")" in
|
|
lint) return;;
|
|
static.go) return;;
|
|
coverage.html) return;;
|
|
esac
|
|
|
|
case "$ext" in
|
|
go) lint_go "${filename}" || lint_result=1
|
|
;;
|
|
esac
|
|
|
|
if [ -z "$IGNORE_TEST_PACKAGES" ]; then
|
|
if [[ "$filename" == *"_test.go" ]]; then
|
|
test_mismatch "${filename}" || lint_result=1
|
|
fi
|
|
fi
|
|
|
|
spell_check "${filename}" || lint_result=1
|
|
|
|
return $lint_result
|
|
}
|
|
|
|
function lint_files {
|
|
local lint_result=0
|
|
while read -r filename; do
|
|
lint "${filename}" || lint_result=1
|
|
done
|
|
exit $lint_result
|
|
}
|
|
|
|
function list_files {
|
|
if [ $# -gt 0 ]; then
|
|
git ls-files --exclude-standard | grep -vE '(^|/)vendor/'
|
|
else
|
|
git diff --cached --name-only
|
|
fi
|
|
}
|
|
|
|
list_files "$@" | lint_files
|