cri-o/.tool/lint
W. Trevor King 64bc1c7226 .tool/lint: Use 'command -v' to detect LINTER presence
There was a 'command -v' check back when this script landed in
aa748b62 (makefile stuff, 2016-09-19, #30), but it was removed in
741873ad (Makefile: suggests install.tools, 2016-09-28, #70).  The
default changed from 'gometalinter' to '${GOPATH}/bin/gometalinter' in
6c9628cd (Build and install from GOPATH, 2017-01-17, #320) and the -f
guard landed in 9c240aed (lint: Exit and give instructions when linter
missing, 2017-09-06, #850).  This commit brings us back to our
original 'command -v' check (in POSIX [1]), which allows support for
both filesystem and $PATH based commands (and shell aliases, etc.).

I've also made the default LINTER more flexible, using the
${parameter:-word} syntax from POSIX [2].  That keeps the default
linter unchanged, but allows callers to set the LINTER environent
variable to override.  For example:

  $ LINTER=gometalinter .tool/lint

will use the linter from your $PATH.

[1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
[2]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02

Signed-off-by: W. Trevor King <wking@tremily.us>
2018-01-25 15:50:53 -08:00

44 lines
1.5 KiB
Bash
Executable file

#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# Create the linter path for use later
LINTER="${LINTER:-${GOPATH}/bin/gometalinter}"
# Make sure gometalinter is installed
if ! command -v ${LINTER} >/dev/null 2>/dev/null; then
echo >&2 "gometalinter must be installed. Please run 'make install.tools' and try again"
exit 1
fi
PKGS=$(find . -type d -not -path . -a -not -iwholename '*.git*' -a -not -iname '.tool' -a -not -iwholename '*vendor*' -a -not -iname 'hack' -a -not -iwholename '*.artifacts*' -a -not -iwholename '*contrib*' -a -not -iwholename '*test*' -a -not -iwholename '*logo*' -a -not -iwholename '*conmon*' -a -not -iwholename '*completions*' -a -not -iwholename '*docs*' -a -not -iwholename '*pause*')
# Execute the linter
${LINTER} \
--concurrency=4\
--enable-gc\
--vendored-linters\
--deadline=600s --disable-all\
--enable=deadcode\
--enable=errcheck\
--enable=goconst\
--enable=gofmt\
--enable=golint\
--enable=ineffassign\
--enable=interfacer\
--enable=megacheck\
--enable=misspell\
--enable=structcheck\
--enable=varcheck\
--enable=vet\
--enable=vetshadow\
--exclude='error return value not checked.*\(errcheck\)$'\
--exclude='declaration of.*err.*shadows declaration.*\(vetshadow\)$'\
--exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$'\
--exclude='duplicate of.*_test.go.*\(dupl\)$'\
--exclude='cmd\/client\/.*\.go.*\(dupl\)$'\
--exclude='vendor\/.*'\
--exclude='server\/seccomp\/.*\.go.*$'\
${PKGS[@]}