Skip to content

Commit

Permalink
Add gocyclo pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome1337 authored and Jérôme Pogeant committed Oct 14, 2019
1 parent 69934e7 commit 48115f0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion .pre-commit-hooks.yaml
Expand Up @@ -22,6 +22,13 @@
files: '\.go$'
language: 'script'
description: "Runs `golint`, requires https://github.com/golang/lint"
- id: go-cyclo
name: 'go-cyclo'
entry: run-go-cyclo.sh
files: '\.go$'
language: 'script'
description: "Runs `gocyclo`, requires https://github.com/fzipp/gocyclo"
args: [-over=15]
- id: validate-toml
name: 'validate toml'
entry: 'tomlv'
Expand Down Expand Up @@ -67,4 +74,4 @@
entry: run-go-build.sh
files: '\.go$'
language: 'script'
description: "Runs `go build`, requires golang"
description: "Runs `go build`, requires golang"
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -15,6 +15,8 @@ Add this to your `.pre-commit-config.yaml`
- id: go-vet
- id: go-lint
- id: go-imports
- id: go-cyclo
args: [-over=15]
- id: validate-toml
- id: no-go-testing
- id: gometalinter
Expand All @@ -29,6 +31,7 @@ Add this to your `.pre-commit-config.yaml`
- `go-vet` - Runs `go vet`, requires golang
- `go-lint` - Runs `golint`, requires https://github.com/golang/lint
- `go-imports` - Runs `goimports`, requires golang.org/x/tools/cmd/goimports
- `go-cyclo` - Runs `gocyclo`, require https://github.com/fzipp/gocyclo
- `validate-toml` - Runs `tomlv`, requires
https://github.com/BurntSushi/toml/tree/master/cmd/tomlv
- `no-go-testing` - Checks that no files are using `testing.T`, if you want
Expand Down
9 changes: 9 additions & 0 deletions run-go-cyclo.sh
@@ -0,0 +1,9 @@
#!/bin/bash

if [ $# -eq 0 ]; then
echo "No arguments supplied"
echo "Please add `args: [-over=15]` in your pre-commit config"
exit 1
fi

exec gocyclo $@

0 comments on commit 48115f0

Please sign in to comment.