-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds pre-commit to improve quality (#184)
* Adds initial hooks * Work on tool install * Actually implements the hooks Does the actual hook implementation but doesn't run them. * --no-verify improve readme with --no-verify tip * RUNS commits hooks * Revert "RUNS commits hooks" This reverts commit 30100f1. * Removes tomlv from tools * Updates RM instructions * Update README.md Co-authored-by: Daniel <[email protected]>
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# install pre-commit `brew install pre-commit` | ||
# install hooks to git `pre-commit install` | ||
# update the hooks `pre-commit autoupdate` | ||
# to run the hooks `pre-commit run --all-files` | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.3.0 | ||
hooks: | ||
- id: check-merge-conflict | ||
- id: check-added-large-files | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- repo: local | ||
hooks: | ||
- id: install-tools | ||
name: "install tools" | ||
entry: "./scripts/install_tools.sh" | ||
language: script | ||
description: "Installs tools needed for go static analysis hooks" | ||
- id: go-vet | ||
name: "go vet" | ||
entry: "./scripts/go_vet.sh" | ||
language: script | ||
description: "Installs tools needed for go static analysis hooks" | ||
|
||
- repo: https://github.com/dnephin/pre-commit-golang | ||
rev: master | ||
hooks: | ||
- id: go-fmt | ||
- id: go-imports | ||
- id: go-cyclo | ||
args: [-over=15] | ||
- id: go-mod-tidy | ||
- id: go-build | ||
- id: go-critic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
pkg=$(go list ./...) | ||
for dir in $(echo $@|xargs -n1 dirname|sort -u); do | ||
go vet $pkg/$dir | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
set -e -o pipefail | ||
|
||
if ! command -v gocyclo &> /dev/null ; then | ||
echo "gocyclo not installed or available in the PATH, installing" >&2 | ||
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest; | ||
fi | ||
|
||
if ! command -v gocritic &> /dev/null ; then | ||
echo "gocritic not installed or available in the PATH, installing" >&2 | ||
go install github.com/go-critic/go-critic/cmd/gocritic@latest; | ||
fi | ||
|
||
if ! command -v goimports &> /dev/null ; then | ||
echo "goimports not installed or available in the PATH, installing" >&2 | ||
go install golang.org/x/tools/cmd/goimports@latest; | ||
fi | ||
|
||
exit 0 |