diff --git a/.golangci.yml b/.golangci.yml index 3a4cf10..d29c6bd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,40 +1,48 @@ run: - timeout: 2m - + allow-parallel-runners: true +issues: + exclude-rules: + - path: controller #достаточное кол-во контекса на уровне контроллеров + linters: + - wrapcheck + - path: transaction #транзакции прозрачны + linters: + - wrapcheck + - path: middleware #отсутствует необходимость оборачивать ошибки + linters: + - wrapcheck + - path: proxy + linters: + - gochecknoglobals + - mnd + - path: httperrors #отсутствует необходимость оборачивать ошибки + linters: + - wrapcheck linters: - disable-all: true - enable: - - asciicheck - - bodyclose - - deadcode - - dogsled - - errcheck - - funlen - - goconst - - gocritic - - gocyclo - - gofmt - - gomnd - - goprintffuncname - - gosimple - - govet - - nakedret - - nestif - - prealloc - - rowserrcheck - - staticcheck - - structcheck - - typecheck - - unconvert - - unparam - - unused - - varcheck - - gosec - - misspell - - whitespace - - exhaustive #смотрит на соответствие между элементами enum и swich кейсами - - exportloopref #for _,p := []int{1, 2, 3} { s.Bar(&p) /* If s stores the pointer, it will be bug.*/ } - - sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. + enable-all: true + disable: + - goimports #у нас собственные правила форматирования импортов + - wsl #расставление пробелов очень индивидуально + - exhaustivestruct #не имеет смысла + - varnamelen #очень индивидуально (db) + - exhaustruct #не имеет смысла + - golint #устарел + - contextcheck #не имеет смысла + - gci #у нас собственные правила форматирования импортов + - gofumpt #у нас собственные правила форматирования импортов + - nolintlint #Goland все равно форматирует с отступом + - nlreturn #не всегда имеет смысл + - godot #не актуально для свагера + - ifshort #приняли решение, что мы так не пишем if err := ...; err != nil {} + - godox #не позволяет оставлять todo + - maligned #аллокацией памяти для структур конфликтует с удобством их чтения + - nosnakecase #не позволяет заводить пакеты используя snake_case + - depguard #не всегда имеет смысл + - dupword #не имеет смысла + - tagalign #не всегда имеет смысл + - musttag #у нас собственные правило: не используем теги, если работаем с пакетом isp-kit/json и с внутренними структурами(между нашими сервисами), при этом теги обязательный для всех внених для нас структур + - perfsprint #мнимая производительность в угоду читаемости + - testpackage linters-settings: funlen: lines: 80 @@ -53,3 +61,6 @@ linters-settings: - "-ST1020" - "-ST1021" - "-ST1022" + testifylint: + disable: + - compares \ No newline at end of file diff --git a/assembly/assembly.go b/assembly/assembly.go index 52119b4..4635fa1 100644 --- a/assembly/assembly.go +++ b/assembly/assembly.go @@ -164,6 +164,7 @@ func (a *Assembly) Closers() []app.Closer { return closers } +// nolint:ireturn func (a *Assembly) redisClient(config conf.Redis) redis.UniversalClient { if config.Sentinel != nil { return redis.NewFailoverClient(&redis.FailoverOptions{ diff --git a/assembly/locator.go b/assembly/locator.go index e0381ff..1e60f73 100644 --- a/assembly/locator.go +++ b/assembly/locator.go @@ -112,7 +112,7 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli ) } entrypoint := middleware.Entrypoint( - config.Http.MaxRequestBodySizeInMb*1024*1024, //nolint:gomnd + config.Http.MaxRequestBodySizeInMb*1024*1024, //nolint:mnd,gomnd handler, l.logger, middleware.EntryPointConfig{ diff --git a/cache/cache_test.go b/cache/cache_test.go index fc373dc..351ee92 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -9,6 +9,7 @@ import ( ) func TestGetBasic(t *testing.T) { + t.Parallel() require := require.New(t) cache := cache.New() @@ -23,6 +24,7 @@ func TestGetBasic(t *testing.T) { } func TestGetExpired(t *testing.T) { + t.Parallel() require := require.New(t) cache := cache.New() @@ -36,6 +38,7 @@ func TestGetExpired(t *testing.T) { } func TestNilValue(t *testing.T) { + t.Parallel() require := require.New(t) cache := cache.New() diff --git a/conf/remote.go b/conf/remote.go index 8f53109..f6099c9 100644 --- a/conf/remote.go +++ b/conf/remote.go @@ -1,3 +1,4 @@ +// nolint:gochecknoinits,lll package conf import ( diff --git a/httperrors/errors.go b/httperrors/errors.go index df42dbe..cf1ce9f 100644 --- a/httperrors/errors.go +++ b/httperrors/errors.go @@ -26,7 +26,7 @@ func (e HttpError) Error() string { } func (e HttpError) WriteError(w http.ResponseWriter) error { - w.Header().Set("content-type", "application/json") + w.Header().Set("Content-Type", "application/json") w.WriteHeader(e.statusCode) data := map[string]interface{}{ "errorCode": http.StatusText(e.statusCode), diff --git a/middleware/middleware.go b/middleware/middleware.go index 5d60db0..1468cc8 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -16,6 +16,7 @@ func (f HandlerFunc) Handle(ctx *request.Context) error { type Middleware func(next Handler) Handler +// nolint:ireturn func Chain(root Handler, middlewares ...Middleware) Handler { for i := len(middlewares) - 1; i >= 0; i-- { root = middlewares[i](root) diff --git a/proxy/grpc.go b/proxy/grpc.go index 1cdc406..1e7b68e 100644 --- a/proxy/grpc.go +++ b/proxy/grpc.go @@ -1,3 +1,4 @@ +// nolint:gochecknoinits package proxy import ( diff --git a/repository/admin.go b/repository/admin.go index 231c1e6..b5368e4 100644 --- a/repository/admin.go +++ b/repository/admin.go @@ -1,3 +1,4 @@ +// nolint:dupl package repository import ( diff --git a/repository/daily_limit.go b/repository/daily_limit.go index d3ed75f..653a47a 100644 --- a/repository/daily_limit.go +++ b/repository/daily_limit.go @@ -27,7 +27,7 @@ func (r DailyLimit) Increment(ctx context.Context, applicationId int, today time } if value == 1 { - err := r.cli.ExpireNX(ctx, key, 24*time.Hour).Err() //nolint:gomnd + err := r.cli.ExpireNX(ctx, key, 24*time.Hour).Err() //nolint:mnd,gomnd if err != nil { return 0, errors.WithMessage(err, "expire nx") } diff --git a/repository/system.go b/repository/system.go index a3ef87c..f441528 100644 --- a/repository/system.go +++ b/repository/system.go @@ -1,3 +1,4 @@ +// nolint:dupl package repository import ( diff --git a/repository/unused/redis_auth_cache.go b/repository/unused/redis_auth_cache.go index aa58355..0d6f711 100644 --- a/repository/unused/redis_auth_cache.go +++ b/repository/unused/redis_auth_cache.go @@ -30,7 +30,7 @@ func (r RedisAuthCache) Get(ctx context.Context, token string) (*domain.AuthData p.Get(ctx, token) return nil }) - if err != nil && err != redis.Nil { + if err != nil && !errors.Is(err, redis.Nil) { return nil, errors.WithMessage(err, "pipelined") } diff --git a/repository/unused/redis_authz_cache.go b/repository/unused/redis_authz_cache.go index b9167ba..5842bfe 100644 --- a/repository/unused/redis_authz_cache.go +++ b/repository/unused/redis_authz_cache.go @@ -29,7 +29,7 @@ func (r RedisAuthzCache) Get(ctx context.Context, applicationId int, endpoint st p.Get(ctx, r.key(applicationId, endpoint)) return nil }) - if err != nil && err != redis.Nil { + if err != nil && !errors.Is(err, redis.Nil) { return false, errors.WithMessage(err, "pipelined") } diff --git a/tests/acceptance_test.go b/tests/acceptance_test.go index c16da81..c2caa73 100644 --- a/tests/acceptance_test.go +++ b/tests/acceptance_test.go @@ -1,3 +1,4 @@ +// nolint:canonicalheader package tests import ( @@ -262,6 +263,7 @@ func (s *HappyPathTestSuite) TestAdminAuthorization() { require.EqualValues(http.StatusForbidden, errResp.StatusCode) } +// nolint:ireturn func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, redis.UniversalClient, *client.Client, *client.Client) { require := test.Assert() redisCli := NewRedis(test) @@ -324,6 +326,7 @@ func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, r } func TestHappyPathTestSuite(t *testing.T) { + t.Parallel() suite.Run(t, new(HappyPathTestSuite)) }