forked from hyperledger/fabric-private-chaincode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolinter.sh
executable file
·66 lines (57 loc) · 2.34 KB
/
golinter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Copyright Greg Haskins All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
# Note: This file is adapted from hyperledger/fabric scripts/golinter.sh (ec81f3e74)
set -e
# shellcheck source=/dev/null
source "$(cd "$(dirname "$0")" && pwd)/functions.sh"
echo "Checking with gofmt"
OUTPUT="$(gofmt -l -s ./..)"
OUTPUT="$(filterExcludedAndGeneratedFiles "$OUTPUT")"
if [ -n "$OUTPUT" ]; then
echo "The following files contain gofmt errors"
echo "$OUTPUT"
echo "The gofmt command 'gofmt -l -s -w' must be run for these files"
exit 1
fi
echo "Checking with goimports"
OUTPUT="$(goimports -l ./..)"
OUTPUT="$(filterExcludedAndGeneratedFiles "$OUTPUT")"
if [ -n "$OUTPUT" ]; then
echo "The following files contain goimports errors"
echo "$OUTPUT"
echo "The goimports command 'goimports -l -w' must be run for these files"
exit 1
fi
# Now that context is part of the standard library, we should use it
# consistently. The only place where the legacy golang.org version should be
# referenced is in the generated protos.
echo "Checking for golang.org/x/net/context"
# shellcheck disable=SC2016
TEMPLATE='{{with $d := .}}{{range $d.Imports}}{{ printf "%s:%s " $d.ImportPath . }}{{end}}{{end}}'
OUTPUT="$(go list -f "$TEMPLATE" ./... | grep 'golang.org/x/net/context' | cut -f1 -d:)"
if [ -n "$OUTPUT" ]; then
echo "The following packages import golang.org/x/net/context instead of context"
echo "$OUTPUT"
exit 1
fi
# We use golang/protobuf but goimports likes to add gogo/protobuf.
# Prevent accidental import of gogo/protobuf.
echo "Checking for github.com/gogo/protobuf"
# shellcheck disable=SC2016
TEMPLATE='{{with $d := .}}{{range $d.Imports}}{{ printf "%s:%s " $d.ImportPath . }}{{end}}{{end}}'
OUTPUT="$(go list -f "$TEMPLATE" ./... | grep 'github.com/gogo/protobuf' | cut -f1 -d:)"
if [ -n "$OUTPUT" ]; then
echo "The following packages import github.com/gogo/protobuf instead of github.com/golang/protobuf"
echo "$OUTPUT"
exit 1
fi
echo "Checking with go vet"
PRINTFUNCS="Debug,Debugf,Print,Printf,Info,Infof,Warning,Warningf,Error,Errorf,Critical,Criticalf,Sprint,Sprintf,Log,Logf,Panic,Panicf,Fatal,Fatalf,Notice,Noticef,Wrap,Wrapf,WithMessage"
OUTPUT="$(go vet -all -printfuncs "$PRINTFUNCS" ./...)"
if [ -n "$OUTPUT" ]; then
echo "The following files contain go vet errors"
echo "$OUTPUT"
exit 1
fi