diff --git a/Makefile b/Makefile index 98e7d9a..5fc2abf 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ all: test clean: @rm -rf $(dir $(realpath $(firstword $(MAKEFILE_LIST))))/binaries -sanity-check: unused misspell lint fmt vet +sanity-check: unused misspell lint fmt vet gocyclo vet: @$(dir $(realpath $(firstword $(MAKEFILE_LIST))))/scripts/go-vet.sh @@ -36,6 +36,9 @@ fmt: lint: @$(dir $(realpath $(firstword $(MAKEFILE_LIST))))/scripts/go-lint.sh +gocyclo: + @$(dir $(realpath $(firstword $(MAKEFILE_LIST))))/scripts/go-cyclo.sh + unused: @$(dir $(realpath $(firstword $(MAKEFILE_LIST))))/scripts/unused.sh diff --git a/scripts/go-cyclo.sh b/scripts/go-cyclo.sh new file mode 100755 index 0000000..185f3c3 --- /dev/null +++ b/scripts/go-cyclo.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Copyright © 2018 Matthias Diester +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +set -euo pipefail + +if ! hash gocyclo > /dev/null 2>&1; then + echo 'Unable to find tool `gocyclo` in the path. Run `go get github.com/fzipp/gocyclo` to install it.' + exit 1 +fi + +BASEDIR="$(cd "$(dirname "$0")/.." && pwd)" + +( cd $BASEDIR && find . -path ./vendor -prune -o -type f -name "*.go" -exec dirname {} \; | sort -u | xargs gocyclo -over 25 )