Skip to content

Commit

Permalink
Update linters config and remove copy paste disabling of linters
Browse files Browse the repository at this point in the history
  • Loading branch information
maranqz committed Aug 20, 2023
1 parent ba3f75c commit 75c8e7d
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 60 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,3 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
args: --timeout=3m -v
# TODO remove, temporary to restore
skip-cache: true
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ issues:
linters:
- staticcheck
text: "SA1029: should not use built-in type string as key for value; define your own type to avoid collisions"
- path: .+/context\.go
linters:
- ireturn
- path: .+/transaction\.go
linters:
- ireturn
source: \) Begin\(ctx
- path: .+/settings\.go
linters:
- ireturn
source: "(?:EnrichBy|SetPropagation|SetCtxKey|CtxKey|SetCancelable|SetTimeout)"
- linters:
- gochecknoglobals
source: "DefaultCtxGetter"
- &internal_text
path: ^internal
text: "var-naming: don't use an underscore in package name"
Expand Down
8 changes: 3 additions & 5 deletions gorm/context.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//go:build go1.16
// +build go1.16

//nolint:ireturn,nolintlint // return Tr for external usage.
//revive:disable:package-comments
package gorm

import (
Expand All @@ -15,20 +13,19 @@ import (
)

// DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey.
//
//nolint:gochecknoglobals
var DefaultCtxGetter = NewCtxGetter(trmcontext.DefaultManager)

// CtxGetter gets Tr from trm.СtxManager by casting trm.Transaction to *gorm.DB.
type CtxGetter struct {
ctxManager trm.СtxManager
}

//revive:disable:exported
// NewCtxGetter returns *CtxGetter to get *gorm.DB from context.Context.
func NewCtxGetter(c trm.СtxManager) *CtxGetter {
return &CtxGetter{ctxManager: c}
}

// DefaultTrOrDB returns Tr(*gorm.DB) from context.Context or DB(*gorm.DB) otherwise.
func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db *gorm.DB) *gorm.DB {
if tr := c.ctxManager.Default(ctx); tr != nil {
return c.convert(tr)
Expand All @@ -37,6 +34,7 @@ func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db *gorm.DB) *gorm.DB {
return db
}

// TrOrDB returns Tr(*gorm.DB) from context.Context by trm.CtxKey or DB(*gorm.DB) otherwise.
func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db *gorm.DB) *gorm.DB {
if tr := c.ctxManager.ByKey(ctx, key); tr != nil {
return c.convert(tr)
Expand Down
4 changes: 2 additions & 2 deletions gorm/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func MustSettings(trms trm.Settings, oo ...Opt) Settings {
return s
}

//revive:disable:exported
func (s Settings) EnrichBy(in trm.Settings) (res trm.Settings) { //nolint:ireturn,nolintlint
// EnrichBy fills nil properties from external Settings.
func (s Settings) EnrichBy(in trm.Settings) (res trm.Settings) {
external, ok := in.(Settings)
if ok {
if s.TxOpts() == nil {
Expand Down
2 changes: 1 addition & 1 deletion gorm/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (t *Transaction) Transaction() interface{} {
}

// Begin nested transaction by save point.
func (t *Transaction) Begin(ctx context.Context, s trm.Settings) (context.Context, trm.Transaction, error) { //nolint:ireturn,nolintlint
func (t *Transaction) Begin(ctx context.Context, s trm.Settings) (context.Context, trm.Transaction, error) {
return NewDefaultFactory(t.tx)(ctx, s)
}

Expand Down
4 changes: 2 additions & 2 deletions mongo/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func MustSettings(trms trm.Settings, oo ...Opt) Settings {
return s
}

//revive:disable:exported
func (s Settings) EnrichBy(in trm.Settings) trm.Settings { //nolint:ireturn,nolintlint
// EnrichBy fills nil properties from external Settings.
func (s Settings) EnrichBy(in trm.Settings) trm.Settings {
external, ok := in.(Settings)
if ok {
if s.SessionOpts() == nil {
Expand Down
8 changes: 3 additions & 5 deletions pgxv4/context.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//go:build go1.16
// +build go1.16

//nolint:ireturn,nolintlint // return Tr for external usage.
//revive:disable:package-comments
package pgxv4

import (
Expand All @@ -13,20 +11,19 @@ import (
)

// DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey.
//
//nolint:gochecknoglobals
var DefaultCtxGetter = NewCtxGetter(trmcontext.DefaultManager)

// CtxGetter gets Tr from trm.СtxManager by casting trm.Transaction to Tr.
type CtxGetter struct {
ctxManager trm.СtxManager
}

//revive:disable:exported
// NewCtxGetter returns *CtxGetter to get Tr from context.Context.
func NewCtxGetter(c trm.СtxManager) *CtxGetter {
return &CtxGetter{ctxManager: c}
}

// DefaultTrOrDB returns Tr from context.Context or DB(Tr) otherwise.
func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db Tr) Tr {
if tr := c.ctxManager.Default(ctx); tr != nil {
return c.convert(tr)
Expand All @@ -35,6 +32,7 @@ func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db Tr) Tr {
return db
}

// TrOrDB returns Tr from context.Context by trm.CtxKey or DB(Tr) otherwise.
func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db Tr) Tr {
if tr := c.ctxManager.ByKey(ctx, key); tr != nil {
return c.convert(tr)
Expand Down
4 changes: 2 additions & 2 deletions pgxv4/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func MustSettings(trms trm.Settings, oo ...Opt) Settings {
return s
}

//revive:disable:exported
func (s Settings) EnrichBy(in trm.Settings) trm.Settings { //nolint:ireturn,nolintlint
// EnrichBy fills nil properties from external Settings.
func (s Settings) EnrichBy(in trm.Settings) trm.Settings {
external, ok := in.(Settings)
if ok {
var emptyTrOpts pgx.TxOptions
Expand Down
2 changes: 1 addition & 1 deletion pgxv4/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (t *Transaction) Transaction() interface{} {
}

// Begin nested transaction by save point.
func (t *Transaction) Begin(ctx context.Context, _ trm.Settings) (context.Context, trm.Transaction, error) { //nolint:ireturn,nolintlint
func (t *Transaction) Begin(ctx context.Context, _ trm.Settings) (context.Context, trm.Transaction, error) {
tx, err := t.tx.Begin(ctx)
if err != nil {
return ctx, nil, err
Expand Down
8 changes: 3 additions & 5 deletions pgxv5/context.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//go:build go1.19
// +build go1.19

//nolint:ireturn,nolintlint // return Tr for external usage.
//revive:disable:package-comments
package pgxv5

import (
Expand All @@ -13,20 +11,19 @@ import (
)

// DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey.
//
//nolint:gochecknoglobals
var DefaultCtxGetter = NewCtxGetter(trmcontext.DefaultManager)

// CtxGetter gets Tr from trm.СtxManager by casting trm.Transaction to Tr.
type CtxGetter struct {
ctxManager trm.СtxManager
}

//revive:disable:exported
// NewCtxGetter returns *CtxGetter to get Tr from context.Context.
func NewCtxGetter(c trm.СtxManager) *CtxGetter {
return &CtxGetter{ctxManager: c}
}

// DefaultTrOrDB returns Tr from context.Context or DB(Tr) otherwise.
func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db Tr) Tr {
if tr := c.ctxManager.Default(ctx); tr != nil {
return c.convert(tr)
Expand All @@ -35,6 +32,7 @@ func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db Tr) Tr {
return db
}

// TrOrDB returns Tr from context.Context by trm.CtxKey or DB(Tr) otherwise.
func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db Tr) Tr {
if tr := c.ctxManager.ByKey(ctx, key); tr != nil {
return c.convert(tr)
Expand Down
4 changes: 2 additions & 2 deletions pgxv5/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func MustSettings(trms trm.Settings, oo ...Opt) Settings {
return s
}

//revive:disable:exported
func (s Settings) EnrichBy(in trm.Settings) trm.Settings { //nolint:ireturn,nolintlint
// EnrichBy fills nil properties from external Settings.
func (s Settings) EnrichBy(in trm.Settings) trm.Settings {
external, ok := in.(Settings)
if ok {
var emptyTrOpts pgx.TxOptions
Expand Down
2 changes: 1 addition & 1 deletion pgxv5/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (t *Transaction) Transaction() interface{} {
}

// Begin nested transaction by save point.
func (t *Transaction) Begin(ctx context.Context, _ trm.Settings) (context.Context, trm.Transaction, error) { //nolint:ireturn,nolintlint
func (t *Transaction) Begin(ctx context.Context, _ trm.Settings) (context.Context, trm.Transaction, error) {
tx, err := t.tx.Begin(ctx)
if err != nil {
return ctx, nil, err
Expand Down
8 changes: 3 additions & 5 deletions redis/context.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//nolint:ireturn,nolintlint // return Tr for external usage.
//revive:disable:package-comments
package redis

import (
Expand All @@ -12,20 +10,19 @@ import (
)

// DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey.
//
//nolint:gochecknoglobals
var DefaultCtxGetter = NewCtxGetter(trmcontext.DefaultManager)

// CtxGetter gets redis.Pipeliner from trm.СtxManager by casting trm.Transaction to redis.UniversalClient.
type CtxGetter struct {
ctxManager trm.СtxManager
}

//revive:disable:exported
// NewCtxGetter returns *CtxGetter to get Cmdable from context.Context.
func NewCtxGetter(c trm.СtxManager) *CtxGetter {
return &CtxGetter{ctxManager: c}
}

// DefaultTrOrDB returns Cmdable from context.Context or DB(redis.Cmdable) otherwise.
func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db redis.Cmdable) redis.Cmdable {
if tr := c.ctxManager.Default(ctx); tr != nil {
return c.convert(tr)
Expand All @@ -34,6 +31,7 @@ func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db redis.Cmdable) redis.C
return db
}

// TrOrDB returns Cmdable from context.Context by trm.CtxKey or DB(redis.Cmdable) otherwise.
func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db redis.Cmdable) redis.Cmdable {
if tr := c.ctxManager.ByKey(ctx, key); tr != nil {
return c.convert(tr)
Expand Down
6 changes: 4 additions & 2 deletions redis/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func MustSettings(trms trm.Settings, oo ...Opt) Settings {
return s
}

//revive:disable:exported
func (s Settings) EnrichBy(in trm.Settings) trm.Settings { //nolint:ireturn,nolintlint
// EnrichBy fills nil properties from external Settings.
func (s Settings) EnrichBy(in trm.Settings) trm.Settings {
external, ok := in.(Settings)
if ok {
if s.IsMultiOrNil() == nil {
Expand All @@ -78,6 +78,7 @@ func (s Settings) EnrichBy(in trm.Settings) trm.Settings { //nolint:ireturn,noli
return s
}

// IsMulti - true uses redis MULTI cmd.
func (s Settings) IsMulti() bool {
if s.isMulti == nil {
return DefaultMulti
Expand All @@ -86,6 +87,7 @@ func (s Settings) IsMulti() bool {
return *s.isMulti
}

// IsMultiOrNil returns IsMulti or nil.
func (s Settings) IsMultiOrNil() *bool {
return s.isMulti
}
Expand Down
8 changes: 3 additions & 5 deletions sql/context.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//nolint:ireturn,nolintlint // return Tr for external usage.
//revive:disable:package-comments
package sql

import (
Expand All @@ -11,20 +9,19 @@ import (
)

// DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey.
//
//nolint:gochecknoglobals
var DefaultCtxGetter = NewCtxGetter(trmcontext.DefaultManager)

// CtxGetter gets Tr from trm.СtxManager by casting trm.Transaction to Tr.
type CtxGetter struct {
ctxManager trm.СtxManager
}

//revive:disable:exported
// NewCtxGetter returns *CtxGetter to get Tr from context.Context.
func NewCtxGetter(c trm.СtxManager) *CtxGetter {
return &CtxGetter{ctxManager: c}
}

// DefaultTrOrDB returns Tr from context.Context or DB(Tr) otherwise.
func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db Tr) Tr {
if tr := c.ctxManager.Default(ctx); tr != nil {
return c.convert(tr)
Expand All @@ -33,6 +30,7 @@ func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db Tr) Tr {
return db
}

// TrOrDB returns Tr from context.Context by trm.CtxKey or DB(Tr) otherwise.
func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db Tr) Tr {
if tr := c.ctxManager.ByKey(ctx, key); tr != nil {
return c.convert(tr)
Expand Down
4 changes: 2 additions & 2 deletions sql/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func MustSettings(trms trm.Settings, oo ...Opt) Settings {
return s
}

//revive:disable:exported
func (s Settings) EnrichBy(in trm.Settings) trm.Settings { //nolint:ireturn,nolintlint
// EnrichBy fills nil properties from external Settings.
func (s Settings) EnrichBy(in trm.Settings) trm.Settings {
external, ok := in.(Settings)
if ok {
if s.TxOpts() == nil {
Expand Down
2 changes: 1 addition & 1 deletion sql/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (t *Transaction) Transaction() interface{} {
}

// Begin nested transaction by save point.
func (t *Transaction) Begin(ctx context.Context, _ trm.Settings) (context.Context, trm.Transaction, error) { //nolint:ireturn,nolintlint
func (t *Transaction) Begin(ctx context.Context, _ trm.Settings) (context.Context, trm.Transaction, error) {
_, err := t.tx.ExecContext(ctx, t.savePoint.Create(t.incrementID()))
if err != nil {
return ctx, nil, err
Expand Down
8 changes: 3 additions & 5 deletions sqlx/context.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//nolint:ireturn,nolintlint // return Tr for external usage.
//revive:disable:package-comments
package sqlx

import (
Expand All @@ -12,20 +10,19 @@ import (
)

// DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey.
//
//nolint:gochecknoglobals
var DefaultCtxGetter = NewCtxGetter(trmcontext.DefaultManager)

// CtxGetter gets Tr from trm.СtxManager by casting trm.Transaction to Tr.
type CtxGetter struct {
ctxManager trm.СtxManager
}

//revive:disable:exported
// NewCtxGetter returns *CtxGetter to get Tr from context.Context.
func NewCtxGetter(c trm.СtxManager) *CtxGetter {
return &CtxGetter{ctxManager: c}
}

// DefaultTrOrDB returns Tr from context.Context or DB(Tr) otherwise.
func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db Tr) Tr {
if tr := c.ctxManager.Default(ctx); tr != nil {
return c.convert(tr)
Expand All @@ -34,6 +31,7 @@ func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db Tr) Tr {
return db
}

// TrOrDB returns Tr from context.Context by trm.CtxKey or DB(Tr) otherwise.
func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db Tr) Tr {
if tr := c.ctxManager.ByKey(ctx, key); tr != nil {
return c.convert(tr)
Expand Down
2 changes: 1 addition & 1 deletion sqlx/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (t *Transaction) Transaction() interface{} {
}

// Begin nested transaction by save point.
func (t *Transaction) Begin(ctx context.Context, _ trm.Settings) (context.Context, trm.Transaction, error) { //nolint:ireturn,nolintlint
func (t *Transaction) Begin(ctx context.Context, _ trm.Settings) (context.Context, trm.Transaction, error) {
_, err := t.tx.ExecContext(ctx, t.savePoint.Create(t.incrementID()))
if err != nil {
return ctx, nil, multierr.Combine(trm.ErrNestedBegin, err)
Expand Down
Loading

0 comments on commit 75c8e7d

Please sign in to comment.