Skip to content

Commit

Permalink
Merge pull request #903 from Mixalight/Switch-golangci-config-from-op…
Browse files Browse the repository at this point in the history
…t-in-linters-to-opt-out

Change golangci to enable all
  • Loading branch information
asmyasnikov authored Dec 10, 2023
2 parents 5377536 + cdad252 commit aec710b
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 80 deletions.
79 changes: 20 additions & 59 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,66 +225,27 @@ linters-settings:
# Default: false
checkExported: true
linters:
disable-all: true
enable:
# - cyclop
enable-all: true
disable:
- godot
- varnamelen
- wrapcheck
- nosnakecase
- deadcode
- golint
- interfacer
- maligned
- ifshort
- structcheck
- exhaustivestruct
- scopelint
- varcheck
- ireturn
- depguard
- dogsled
# - dupl
- errcheck
- errorlint
# - exhaustive
# - exhaustivestruct
# - forbidigo
# - funlen
# - gci
# - gocognit
- goconst
- gocritic
- gocyclo
# - godot
- godox
- gofmt # On why gofmt when goimports is enabled - https://github.com/golang/go/issues/21476
- gofumpt
- goheader
- goimports
# - gomnd
# - gomoddirectives
# - gomodguard
- gosec
- gosimple
- govet
- depguard
# - ifshort
# - ireturn
- lll
- makezero
- misspell
- ineffassign
- misspell
- nakedret
- nestif
# - nilnil
# - nlreturn
- nolintlint
- prealloc
- predeclared
- rowserrcheck
- revive
- staticcheck
- stylecheck
# - tagliatelle
# - testpackage
# - thelper
# - tenv
- typecheck
- unconvert
- unparam
- unused
# - varnamelen
- whitespace
# - wrapcheck
# - wsl
- wsl
- exhaustruct
- gci
- paralleltest #need be enabled

issues:
# List of regexps of issue texts to exclude, empty list by default.
Expand Down
2 changes: 2 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
// Interface and list of clients may be changed in the future
//
// Deprecated: use directly *Driver type from ydb.Open instead
//
//nolint:interfacebloat
type Connection interface {
// Endpoint returns initial endpoint
Endpoint() string
Expand Down
29 changes: 20 additions & 9 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ func (d *Driver) trace() *trace.Driver {
if d.config != nil {
return d.config.Trace()
}

return &trace.Driver{}
}

// Close closes Driver and clear resources
//
//nolint:nonamedreturns
func (d *Driver) Close(ctx context.Context) (finalErr error) {
onDone := trace.DriverOnClose(d.trace(), &ctx, stack.FunctionID(""))
defer func() {
Expand Down Expand Up @@ -214,6 +217,8 @@ func (d *Driver) Topic() topic.Client {
// "grpc[s]://{endpoint}/{database}[?param=value]"
//
// See sugar.DSN helper for make dsn from endpoint and database
//
//nolint:nonamedreturns
func Open(ctx context.Context, dsn string, opts ...Option) (_ *Driver, err error) {
d, err := newConnectionFromOptions(ctx, append(
[]Option{
Expand Down Expand Up @@ -246,12 +251,15 @@ func MustOpen(ctx context.Context, dsn string, opts ...Option) *Driver {
if err != nil {
panic(err)
}

return db
}

// New connects to database and return driver runtime holder
//
// Deprecated: use Open with required param connectionString instead
//
//nolint:nonamedreturns
func New(ctx context.Context, opts ...Option) (_ *Driver, err error) {
d, err := newConnectionFromOptions(ctx, opts...)
if err != nil {
Expand All @@ -274,6 +282,7 @@ func New(ctx context.Context, opts ...Option) (_ *Driver, err error) {
return d, nil
}

//nolint:cyclop, nonamedreturns
func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, err error) {
ctx, driverCtxCancel := xcontext.WithCancel(xcontext.WithoutDeadline(ctx))
defer func() {
Expand Down Expand Up @@ -321,16 +330,16 @@ func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, e
}
if d.logger != nil {
for _, opt := range []Option{
WithTraceDriver(log.Driver(d.logger, d.loggerDetails, d.loggerOpts...)),
WithTraceTable(log.Table(d.logger, d.loggerDetails, d.loggerOpts...)),
WithTraceScripting(log.Scripting(d.logger, d.loggerDetails, d.loggerOpts...)),
WithTraceDriver(log.Driver(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck
WithTraceTable(log.Table(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck
WithTraceScripting(log.Scripting(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck
WithTraceScheme(log.Scheme(d.logger, d.loggerDetails, d.loggerOpts...)),
WithTraceCoordination(log.Coordination(d.logger, d.loggerDetails, d.loggerOpts...)),
WithTraceRatelimiter(log.Ratelimiter(d.logger, d.loggerDetails, d.loggerOpts...)),
WithTraceDiscovery(log.Discovery(d.logger, d.loggerDetails, d.loggerOpts...)),
WithTraceTopic(log.Topic(d.logger, d.loggerDetails, d.loggerOpts...)),
WithTraceDatabaseSQL(log.DatabaseSQL(d.logger, d.loggerDetails, d.loggerOpts...)),
WithTraceRetry(log.Retry(d.logger, d.loggerDetails, d.loggerOpts...)),
WithTraceDiscovery(log.Discovery(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck
WithTraceTopic(log.Topic(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck
WithTraceDatabaseSQL(log.DatabaseSQL(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck
WithTraceRetry(log.Retry(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck
} {
if opt != nil {
err = opt(ctx, d)
Expand All @@ -341,16 +350,18 @@ func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, e
}
}
d.config = config.New(d.options...)

return d, nil
}

//nolint:cyclop, nonamedreturns, funlen
func (d *Driver) connect(ctx context.Context) (err error) {
if d.config.Endpoint() == "" {
return xerrors.WithStackTrace(errors.New("configuration: empty dial address"))
return xerrors.WithStackTrace(errors.New("configuration: empty dial address")) //nolint:goerr113
}

if d.config.Database() == "" {
return xerrors.WithStackTrace(errors.New("configuration: empty database"))
return xerrors.WithStackTrace(errors.New("configuration: empty database")) //nolint:goerr113
}

if d.userInfo != nil {
Expand Down
2 changes: 2 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func IsOperationErrorSchemeError(err error) bool {
}

// IsOperationErrorTransactionLocksInvalidated checks does err a TLI issue
//
//nolint:nonamedreturns
func IsOperationErrorTransactionLocksInvalidated(err error) (isTLI bool) {
return xerrors.IsOperationErrorTransactionLocksInvalidated(err)
}
Expand Down
Loading

0 comments on commit aec710b

Please sign in to comment.