Skip to content

Commit

Permalink
Add gocyclo
Browse files Browse the repository at this point in the history
The `gocyclo` tool call can be used via a make target to test function
complexity.
  • Loading branch information
HeavyWombat committed Apr 24, 2018
1 parent 3365479 commit e7bf019
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
32 changes: 32 additions & 0 deletions scripts/go-cyclo.sh
Original file line number Diff line number Diff line change
@@ -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 )

0 comments on commit e7bf019

Please sign in to comment.