diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 448a7c1d1..0d7c1d0ae 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -59,7 +59,7 @@ jobs: go-version: 1.25.x cache: false # managed by golangci-lint - - uses: golangci/golangci-lint-action@v6 + - uses: golangci/golangci-lint-action@v8 name: Install golangci-lint with: version: latest diff --git a/.golangci.yml b/.golangci.yml index 74faaa71d..3cb22379d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,77 +1,83 @@ -output: - # Make output more digestible with quickfix in vim/emacs/etc. - sort-results: true - print-issued-lines: false - +version: "2" +formatters: + enable: + - gofumpt + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ linters: # We'll track the golangci-lint default linters manually # instead of letting them change without our control. - disable-all: true + default: none enable: # golangci-lint defaults: - errcheck - - gosimple - govet - ineffassign - - staticcheck + - staticcheck # gosimple has been merged inside the staticcheck. - unused # Our own extras: - - gofumpt - nolintlint # lints nolint directives - revive + settings: + govet: + # These govet checks are disabled by default, but they're useful. + enable: + - nilness + - reflectvaluecompare + - sortslice + - unusedwrite + + errcheck: + exclude-functions: + # These methods can not fail. + # They operate on an in-memory buffer. + - (*go.uber.org/zap/buffer.Buffer).Write + - (*go.uber.org/zap/buffer.Buffer).WriteByte + - (*go.uber.org/zap/buffer.Buffer).WriteString -linters-settings: - govet: - # These govet checks are disabled by default, but they're useful. - enable: - - nilness - - reflectvaluecompare - - sortslice - - unusedwrite + - (*go.uber.org/zap/zapio.Writer).Close + - (*go.uber.org/zap/zapio.Writer).Sync + - (*go.uber.org/zap/zapio.Writer).Write + # Write to zapio.Writer cannot fail, + # so io.WriteString on it cannot fail. + - io.WriteString(*go.uber.org/zap/zapio.Writer) - errcheck: - exclude-functions: - # These methods can not fail. - # They operate on an in-memory buffer. - - (*go.uber.org/zap/buffer.Buffer).Write - - (*go.uber.org/zap/buffer.Buffer).WriteByte - - (*go.uber.org/zap/buffer.Buffer).WriteString + # Writing a plain string to a fmt.State cannot fail. + - io.WriteString(fmt.State) + exclusions: + generated: lax + # Don't ignore some of the issues that golangci-lint considers okay. + # This includes documenting all exported entities. + # exclude-use-default: false - - (*go.uber.org/zap/zapio.Writer).Close - - (*go.uber.org/zap/zapio.Writer).Sync - - (*go.uber.org/zap/zapio.Writer).Write - # Write to zapio.Writer cannot fail, - # so io.WriteString on it cannot fail. - - io.WriteString(*go.uber.org/zap/zapio.Writer) + rules: + # Don't warn on unused parameters. + # Parameter names are useful; replacing them with '_' is undesirable. + - linters: [revive] + text: 'unused-parameter: parameter \S+ seems to be unused, consider removing or renaming it as _' - # Writing a plain string to a fmt.State cannot fail. - - io.WriteString(fmt.State) + # staticcheck already has smarter checks for empty blocks. + # revive's empty-block linter has false positives. + # For example, a riting this, the following is not allowed. + # for foo() { } + - linters: [revive] + text: 'empty-block: this block is empty, you can remove it' + # Ignore logger.Sync() errcheck failures in example_test.go + # since those are intended to be uncomplicated examples. + - linters: [errcheck] + path: example_test.go + text: 'Error return value of `logger.Sync` is not checked' + paths: + - third_party$ + - builtin$ + - examples$ issues: # Print all issues reported by all linters. max-issues-per-linter: 0 max-same-issues: 0 - - # Don't ignore some of the issues that golangci-lint considers okay. - # This includes documenting all exported entities. - exclude-use-default: false - - exclude-rules: - # Don't warn on unused parameters. - # Parameter names are useful; replacing them with '_' is undesirable. - - linters: [revive] - text: 'unused-parameter: parameter \S+ seems to be unused, consider removing or renaming it as _' - - # staticcheck already has smarter checks for empty blocks. - # revive's empty-block linter has false positives. - # For example, as of writing this, the following is not allowed. - # for foo() { } - - linters: [revive] - text: 'empty-block: this block is empty, you can remove it' - - # Ignore logger.Sync() errcheck failures in example_test.go - # since those are intended to be uncomplicated examples. - - linters: [errcheck] - path: example_test.go - text: 'Error return value of `logger.Sync` is not checked' diff --git a/zapcore/field_test.go b/zapcore/field_test.go index bbbc97d5f..618df354a 100644 --- a/zapcore/field_test.go +++ b/zapcore/field_test.go @@ -69,11 +69,12 @@ func (o *obj) String() string { return "nil obj" } - if o.kind == 1 { + switch o.kind { + case 1: panic("panic with string") - } else if o.kind == 2 { + case 2: panic(errors.New("panic with error")) - } else if o.kind == 3 { + case 3: // panic with an arbitrary object that causes a panic itself // when being converted to a string panic((*url.URL)(nil)) diff --git a/zapcore/lazy_with.go b/zapcore/lazy_with.go index c0d63a0f5..73db6de8f 100644 --- a/zapcore/lazy_with.go +++ b/zapcore/lazy_with.go @@ -23,7 +23,7 @@ package zapcore import "sync" type lazyWithCore struct { - core Core + core Core sync.Once fields []Field } @@ -38,7 +38,7 @@ func NewLazyWith(core Core, fields []Field) Core { } func (d *lazyWithCore) initOnce() { - d.Once.Do(func() { + d.Do(func() { d.core = d.core.With(d.fields) }) } diff --git a/zaptest/logger_test.go b/zaptest/logger_test.go index 40e368b50..7470606e5 100644 --- a/zaptest/logger_test.go +++ b/zaptest/logger_test.go @@ -173,7 +173,7 @@ func (t *testLogSpy) Logf(format string, args ...interface{}) { m := fmt.Sprintf(format, args...) m = m[strings.IndexByte(m, '\t')+1:] t.Messages = append(t.Messages, m) - t.TB.Log(m) + t.Log(m) } func (t *testLogSpy) AssertMessages(msgs ...string) {