Skip to content

Commit

Permalink
linting code
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-tacquet committed Feb 18, 2021
1 parent 37f6a6c commit 00e0986
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 14 deletions.
145 changes: 145 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
linters-settings:
dupl:
threshold: 150
funlen:
lines: 140
statements: 60
gci:
local-prefixes: github.com/golangci/golangci-lint
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 30
goimports:
local-prefixes: github.com/golangci/golangci-lint
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exhaustive
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- nakedret
- noctx
- nolintlint
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- godot
- prealloc
- wsl
- maligned
- goerr113

# don't enable:
# - asciicheck
# - gochecknoglobals
# - gocognit
# - godox
# - nestif
# - testpackage
# - gomnd
# - misspell

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd

# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"

# TODO temporary rule, must be removed
# seems related to v0.34.1, but I was not able to reproduce locally,
# I was also not able to reproduce in the CI of a fork,
# only the golangci-lint CI seems to be affected by this invalid analysis.
- path: pkg/golinters/scopelint.go
text: 'directive `//nolint:interfacer` is unused for linter interfacer'

run:
skip-dirs:
- test/testdata_etc
- internal/cache
- internal/renameio
- internal/robustio

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.23.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
26 changes: 13 additions & 13 deletions gormlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"gorm.io/gorm/utils"
)

// gormlog must match gorm logger.Interface to be compatible with gorm.
// gormlog can be assigned in gorm configuration (see example in README.md)
type gormlog struct {
// Gormlog must match gorm logger.Interface to be compatible with gorm.
// Gormlog can be assigned in gorm configuration (see example in README.md).
type Gormlog struct {
// SkipErrRecordNotFound if set to true, errors of type gorm.ErrRecordNotFound will be ignored.
SkipErrRecordNotFound bool

Expand All @@ -27,9 +27,9 @@ type gormlog struct {
opts options
}

// NewGormlog create an instance of
func NewGormlog(opts ...Option) *gormlog {
gl := &gormlog{
// NewGormlog create an instance of.
func NewGormlog(opts ...Option) *Gormlog {
gl := &Gormlog{
opts: defaultOptions(),
}

Expand All @@ -40,13 +40,13 @@ func NewGormlog(opts ...Option) *gormlog {
return gl
}

// LogMod implementation log mode
func (gl *gormlog) LogMode(logger.LogLevel) logger.Interface {
// LogMod implementation log mode.
func (gl *Gormlog) LogMode(logger.LogLevel) logger.Interface {
return gl
}

// Info implementaiton of info log level
func (gl *gormlog) Info(ctx context.Context, msg string, args ...interface{}) {
func (gl *Gormlog) Info(ctx context.Context, msg string, args ...interface{}) {
if gl.opts.lr != nil {
gl.opts.lr.WithContext(ctx).Infof(msg, args...)
}
Expand All @@ -57,7 +57,7 @@ func (gl *gormlog) Info(ctx context.Context, msg string, args ...interface{}) {
}

// Warn implementaiton of warn log level
func (gl *gormlog) Warn(ctx context.Context, msg string, args ...interface{}) {
func (gl *Gormlog) Warn(ctx context.Context, msg string, args ...interface{}) {
if gl.opts.lr != nil {
gl.opts.lr.WithContext(ctx).Warnf(msg, args...)
}
Expand All @@ -67,8 +67,8 @@ func (gl *gormlog) Warn(ctx context.Context, msg string, args ...interface{}) {
}
}

// Error gormlog of error log level
func (gl *gormlog) Error(ctx context.Context, msg string, args ...interface{}) {
// Error Gormlog of error log level
func (gl *Gormlog) Error(ctx context.Context, msg string, args ...interface{}) {
if gl.opts.lr != nil {
gl.opts.lr.WithContext(ctx).Errorf(msg, args...)
}
Expand All @@ -79,7 +79,7 @@ func (gl *gormlog) Error(ctx context.Context, msg string, args ...interface{}) {
}

// Trace implementaiton of trace log level
func (gl *gormlog) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) {
func (gl *Gormlog) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) {
// retrive sql string
traceLog, _ := fc()

Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func newGormLogOption(f func(*options)) *funcOption {
}

// WithLogrusEntry Option (not compatible with WithLogrus) used to specify your logrusEntry instance.
// If you don't set a logrusEntry isntance or if your logrusInstance is nil, gormlog will consider
// If you don't set a logrusEntry isntance or if your logrusInstance is nil, Gormlog will consider
// that you want log to be printed on stdout.
// It's useful on developpement purposes when you want to see your logs directly in terminal.
func WithLogrusEntry(logrusEntry *logrus.Entry) Option {
Expand Down

0 comments on commit 00e0986

Please sign in to comment.