mirror of
https://github.com/PuerkitoBio/goquery.git
synced 2024-04-21 12:31:36 +00:00
update pre-commit hook with other static checks
This commit is contained in:
+42
-27
@@ -1,37 +1,52 @@
|
||||
#!/bin/sh
|
||||
# Copyright 2012 The Go Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
# git gofmt pre-commit hook
|
||||
#
|
||||
# To use, store as .git/hooks/pre-commit inside your repository and make sure
|
||||
# it has execute permissions.
|
||||
#
|
||||
# This script does not handle file names that contain spaces.
|
||||
echo ">>> golint"
|
||||
for dir in $(go list ./... | grep -v /vendor/)
|
||||
do
|
||||
golint "${dir}"
|
||||
done
|
||||
echo "<<< golint"
|
||||
echo
|
||||
|
||||
# golint is purely informational, it doesn't fail with exit code != 0 if it finds something,
|
||||
# because it may find a lot of false positives. Just print out its result for information.
|
||||
echo "lint result (informational only):"
|
||||
golint .
|
||||
echo ">>> go vet"
|
||||
go vet $(go list ./... | grep -v /vendor/)
|
||||
echo "<<< go vet"
|
||||
echo
|
||||
|
||||
# go vet returns 1 if an error was found. Exit the hook with this exit code.
|
||||
go vet ./...
|
||||
vetres=$?
|
||||
echo ">>> gosimple"
|
||||
gosimple $(go list ./... | grep -v /vendor/)
|
||||
echo "<<< gosimple"
|
||||
echo
|
||||
|
||||
echo ">>> staticcheck"
|
||||
staticcheck $(go list ./... | grep -v /vendor/)
|
||||
echo "<<< staticcheck"
|
||||
echo
|
||||
|
||||
echo ">>> unused"
|
||||
unused $(go list ./... | grep -v /vendor/)
|
||||
echo "<<< unused"
|
||||
echo
|
||||
|
||||
echo ">>> gas"
|
||||
gas $(find . -name "*.go" | grep -v /vendor/ | grep -v '_test.go$')
|
||||
echo "<<< gas"
|
||||
echo
|
||||
|
||||
# Check for gofmt problems and report if any.
|
||||
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$')
|
||||
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$' | grep -v /vendor/)
|
||||
[ -z "$gofiles" ] && echo "EXIT $vetres" && exit $vetres
|
||||
|
||||
unformatted=$(gofmt -l $gofiles)
|
||||
[ -z "$unformatted" ] && echo "EXIT $vetres" && exit $vetres
|
||||
if [ -n "$gofiles" ]; then
|
||||
unformatted=$(gofmt -l $gofiles)
|
||||
|
||||
# Some files are not gofmt'd. Print message and fail.
|
||||
if [ -n "$unformatted" ]; then
|
||||
# Some files are not gofmt'd.
|
||||
echo >&2 "Go files must be formatted with gofmt. Please run:"
|
||||
for fn in $unformatted; do
|
||||
echo >&2 " gofmt -w $PWD/$fn"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
echo
|
||||
|
||||
echo >&2 "Go files must be formatted with gofmt. Please run:"
|
||||
for fn in $unformatted; do
|
||||
echo >&2 " gofmt -w $PWD/$fn"
|
||||
done
|
||||
|
||||
echo "EXIT 1"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user