diff --git a/pkg/api/login.go b/pkg/api/login.go index f6c3e802988..65ace1b2b83 100644 --- a/pkg/api/login.go +++ b/pkg/api/login.go @@ -164,7 +164,7 @@ func tryGetEncryptedCookie(ctx *m.ReqContext, cookieName string) (string, bool) return "", false } - decryptedError, err := util.Decrypt([]byte(decoded), setting.SecretKey) + decryptedError, err := util.Decrypt(decoded, setting.SecretKey) return string(decryptedError), err == nil } diff --git a/pkg/infra/remotecache/database_storage_test.go b/pkg/infra/remotecache/database_storage_test.go index 455616ae664..642e21d064e 100644 --- a/pkg/infra/remotecache/database_storage_test.go +++ b/pkg/infra/remotecache/database_storage_test.go @@ -66,7 +66,8 @@ func TestSecondSet(t *testing.T) { obj := &CacheableStruct{String: "hey!"} err = db.Set("killa-gorilla", obj, 0) - err = db.Set("killa-gorilla", obj, 0) + assert.Equal(t, err, nil) + err = db.Set("killa-gorilla", obj, 0) assert.Equal(t, err, nil) } diff --git a/pkg/infra/remotecache/remotecache_test.go b/pkg/infra/remotecache/remotecache_test.go index b3ff41375ec..7cdd05288e9 100644 --- a/pkg/infra/remotecache/remotecache_test.go +++ b/pkg/infra/remotecache/remotecache_test.go @@ -64,6 +64,7 @@ func canPutGetAndDeleteCachedObjects(t *testing.T, client CacheStorage) { assert.Equal(t, err, nil, "expected nil. got: ", err) data, err := client.Get("key1") + assert.Equal(t, err, nil) s, ok := data.(CacheableStruct) assert.Equal(t, ok, true) diff --git a/pkg/services/auth/auth_token.go b/pkg/services/auth/auth_token.go index 255866a9ba0..740e5081668 100644 --- a/pkg/services/auth/auth_token.go +++ b/pkg/services/auth/auth_token.go @@ -149,7 +149,7 @@ func (s *UserAuthTokenService) TryRotateToken(token *models.UserToken, clientIP, now := getTime() - needsRotation := false + var needsRotation bool rotatedAt := time.Unix(model.RotatedAt, 0) if model.AuthTokenSeen { needsRotation = rotatedAt.Before(now.Add(-time.Duration(s.Cfg.TokenRotationIntervalMinutes) * time.Minute)) diff --git a/pkg/services/quota/quota.go b/pkg/services/quota/quota.go index ff2528e31e8..b65ad932699 100644 --- a/pkg/services/quota/quota.go +++ b/pkg/services/quota/quota.go @@ -48,7 +48,7 @@ func (qs *QuotaService) QuotaReached(c *m.ReqContext, target string) (bool, erro return false, err } - if int64(usedSessions) > scope.DefaultLimit { + if usedSessions > scope.DefaultLimit { c.Logger.Debug("Sessions limit reached", "active", usedSessions, "limit", scope.DefaultLimit) return true, nil } diff --git a/scripts/backend-lint.sh b/scripts/backend-lint.sh index dcddaaddc70..a6ddfcee9e5 100755 --- a/scripts/backend-lint.sh +++ b/scripts/backend-lint.sh @@ -1,39 +1,42 @@ #!/bin/bash function exit_if_fail { - command=$@ - echo "Executing '$command'" - eval $command - rc=$? - if [ $rc -ne 0 ]; then - echo "'$command' returned $rc." - exit $rc - fi + command=$@ + echo "Executing '$command'" + eval $command + rc=$? + if [ $rc -ne 0 ]; then + echo "'$command' returned $rc." + exit $rc + fi } go get -u github.com/alecthomas/gometalinter -go get -u github.com/tsenart/deadcode go get -u github.com/jgautheron/goconst/cmd/goconst -go get -u github.com/gordonklaus/ineffassign -go get -u github.com/opennota/check/cmd/structcheck -go get -u github.com/mdempsky/unconvert -go get -u github.com/opennota/check/cmd/varcheck go get -u honnef.co/go/tools/cmd/staticcheck go get -u github.com/mgechev/revive go get -u github.com/securego/gosec/cmd/gosec/... +go get -u github.com/golangci/golangci-lint/cmd/golangci-lint +# use gometalinter when lints are not available in golangci or +# when gometalinter is better. Eg. goconst for gometalinter does not lint test files +# which is not desired. exit_if_fail gometalinter --enable-gc --vendor --deadline 10m --disable-all \ - --enable=deadcode \ - --enable=goconst \ - --enable=gofmt \ - --enable=ineffassign \ - --enable=structcheck \ - --enable=unconvert \ - --enable=varcheck \ + --enable=goconst\ --enable=staticcheck +# use golangci-when possible +exit_if_fail golangci-lint run --deadline 10m --disable-all \ + --enable=deadcode\ + --enable=gofmt\ + --enable=ineffassign\ + --enable=structcheck\ + --enable=unconvert\ + --enable=varcheck + exit_if_fail go vet ./pkg/... -exit_if_fail revive -formatter stylish -config ./conf/revive.toml + +exit_if_fail revive -formatter stylish -config ./scripts/revive.toml # TODO recheck the rules and leave only necessary exclusions exit_if_fail gosec -quiet -exclude=G104,G107,G201,G202,G204,G301,G302,G304,G402,G501,G505,G401 ./pkg/... diff --git a/conf/revive.toml b/scripts/revive.toml similarity index 100% rename from conf/revive.toml rename to scripts/revive.toml