Skip to content

Commit

Permalink
[FAB-11131] lint all code, enable all vet checks
Browse files Browse the repository at this point in the history
Change-Id: I922e2fa2b916325ccea7087a5bdb1e6c37fd0238
Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm committed Jul 16, 2018
1 parent e9ed0db commit 83fc11a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 44 deletions.
2 changes: 1 addition & 1 deletion integration/e2e/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func SetACLPolicy(network *nwo.Network, channel, policyName, policy string) {
ModPolicy: "Admins",
Value: utils.MarshalOrPanic(&pb.ACLs{
Acls: map[string]*pb.APIResource{
policyName: &pb.APIResource{PolicyRef: policy},
policyName: {PolicyRef: policy},
},
}),
}
Expand Down
70 changes: 27 additions & 43 deletions scripts/golinter.sh
Original file line number Diff line number Diff line change
@@ -1,57 +1,41 @@
#!/bin/bash -e
#!/bin/bash

# Copyright Greg Haskins All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0

declare -a arr=(
"./bccsp"
"./cmd"
"./common"
"./core"
"./discovery"
"./events"
"./examples"
"./gossip"
"./idemix"
"./msp"
"./orderer"
"./peer"
"./protos"
)
set -e

# place the Go build cache directory into the default build tree if it exists
if [ -d "${GOPATH}/src/github.com/hyperledger/fabric/.build" ]; then
export GOCACHE="${GOPATH}/src/github.com/hyperledger/fabric/.build/go-cache"
fi

for i in "${arr[@]}"
do
echo ">>>Checking code under $i/"
fabric_dir="$(cd "$(dirname "$0")/.." && pwd)"
source_dirs=$(go list -f '{{.Dir}}' ./... | sed s,"${fabric_dir}".,,g | cut -f 1 -d / | sort -u)

echo "Checking with gofmt"
OUTPUT="$(gofmt -l -s ./$i | grep -v testdata/ || true)"
if [[ $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 gofmt"
OUTPUT="$(gofmt -l -s ${source_dirs})"
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 -srcdir $GOPATH/src/github.com/hyperledger/fabric -l $i | grep -v testdata/ || true )"
if [[ $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
echo "Checking with goimports"
OUTPUT="$(goimports -l ${source_dirs} | grep -Ev '(^|/)testdata/' || true)"
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

echo "Checking with go vet"
OUTPUT="$(go vet -composites=false $i/...)"
if [[ $OUTPUT ]]; then
echo "The following files contain go vet errors"
echo $OUTPUT
exit 1
fi
done
echo "Checking with go vet"
OUTPUT="$(go vet ./...)"
if [ -n "$OUTPUT" ]; then
echo "The following files contain go vet errors"
echo $OUTPUT
exit 1
fi

0 comments on commit 83fc11a

Please sign in to comment.