[NOD-1521] use staticcheck (#1015)

* [NOD-1521] Use static check as part of jenkins to check for swallowed errors

* [NOD-1521] added staticcheck installation

* [NOD-1521] Fix static check errors

Co-authored-by: Ori Newman <orinewman1@gmail.com>
This commit is contained in:
oudeis 2020-11-10 15:59:35 +00:00 committed by GitHub
parent 23c1ea6c31
commit 8290fadd3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 5 deletions

View File

@ -222,6 +222,10 @@ func (flow *handleRelayInvsFlow) processAndRelayBlock(requestQueue *hashesQueueS
return err
}
selectedTipBlueScore, err := blocks.ExtractBlueScore(virtualSelectedParent)
if err != nil {
return err
}
if blueScore > selectedTipBlueScore+maxOrphanBlueScoreDiff {
log.Infof("Orphan block %s has blue score %d and the selected tip blue score is "+
"%d. Ignoring orphans with a blue score difference from the selected tip greater than %d",

View File

@ -6,7 +6,8 @@ RUN mkdir -p /go/src/github.com/kaspanet/kaspad
WORKDIR /go/src/github.com/kaspanet/kaspad
RUN apk add --no-cache curl git openssh binutils gcc musl-dev
RUN go get -u golang.org/x/lint/golint
RUN go get -u golang.org/x/lint/golint \
honnef.co/go/tools/cmd/staticcheck
COPY go.mod .
COPY go.sum .
@ -20,6 +21,7 @@ WORKDIR /go/src/github.com/kaspanet/kaspad/cmd/kaspactl
RUN GOFMT_RESULT=`go fmt ./...`; echo $GOFMT_RESULT; test -z "$GOFMT_RESULT"
RUN go vet ./...
RUN golint -set_exit_status ./...
RUN staticcheck -checks SA4006 ./...
RUN GOOS=linux go build -a -installsuffix cgo -o kaspactl .
# --- multistage docker build: stage #2: runtime image

View File

@ -6,7 +6,8 @@ RUN mkdir -p /go/src/github.com/kaspanet/kaspad
WORKDIR /go/src/github.com/kaspanet/kaspad
RUN apk add --no-cache curl git openssh binutils gcc musl-dev
RUN go get -u golang.org/x/lint/golint
RUN go get -u golang.org/x/lint/golint \
honnef.co/go/tools/cmd/staticcheck
COPY go.mod .
COPY go.sum .
@ -20,6 +21,7 @@ WORKDIR /go/src/github.com/kaspanet/kaspad/cmd/kaspaminer
RUN GOFMT_RESULT=`go fmt ./...`; echo $GOFMT_RESULT; test -z "$GOFMT_RESULT"
RUN go vet ./...
RUN golint -set_exit_status ./...
RUN staticcheck -checks SA4006 ./...
RUN GOOS=linux go build -a -installsuffix cgo -o kaspaminer .
# --- multistage docker build: stage #2: runtime image

View File

@ -10,7 +10,8 @@ RUN go get -u golang.org/x/lint/golint \
github.com/kisielk/errcheck \
github.com/opennota/check/cmd/aligncheck \
github.com/opennota/check/cmd/structcheck \
github.com/opennota/check/cmd/varcheck
github.com/opennota/check/cmd/varcheck \
honnef.co/go/tools/cmd/staticcheck
COPY go.mod .
COPY go.sum .
@ -25,6 +26,7 @@ RUN golint -set_exit_status ./...
# RUN aligncheck ./...
# RUN structcheck -e ./...
# RUN varcheck -e ./...
RUN staticcheck -checks SA4006 ./...
RUN GOOS=linux go build -a -installsuffix cgo -o kaspad .
# Remove the line below and uncomment the line after it for testing with coverage

View File

@ -81,7 +81,7 @@ func TestLevelDBTransactionSanity(t *testing.T) {
// Get from the key previously put to. Since the tx is not
// yet committed, this should return ErrNotFound.
getData, err := ldb.Get(key)
_, err = ldb.Get(key)
if err == nil {
t.Fatalf("TestLevelDBTransactionSanity: Get " +
"unexpectedly succeeded")
@ -100,7 +100,7 @@ func TestLevelDBTransactionSanity(t *testing.T) {
// Get from the key previously put to. Now that the tx was
// committed, this should succeed.
getData, err = ldb.Get(key)
getData, err := ldb.Get(key)
if err != nil {
t.Fatalf("TestLevelDBTransactionSanity: Get "+
"returned unexpected error: %s", err)