From 250f1181aedfc33848aae3d02bc720fa8e41182c Mon Sep 17 00:00:00 2001 From: junya koyama Date: Wed, 17 Sep 2025 23:43:53 +0900 Subject: [PATCH 1/8] golangci.yml auto migration Signed-off-by: junya koyama --- .golangci.yml | 114 +++++++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 67 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 74faaa71d..54c606e55 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,77 +1,57 @@ -output: - # Make output more digestible with quickfix in vim/emacs/etc. - sort-results: true - print-issued-lines: false - +version: "2" 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 + - nolintlint + - revive - staticcheck - unused - - # Our own extras: - - gofumpt - - nolintlint # lints nolint directives - - revive - -linters-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 - - - (*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) - - # Writing a plain string to a fmt.State cannot fail. - - io.WriteString(fmt.State) - + settings: + errcheck: + exclude-functions: + - (*go.uber.org/zap/buffer.Buffer).Write + - (*go.uber.org/zap/buffer.Buffer).WriteByte + - (*go.uber.org/zap/buffer.Buffer).WriteString + - (*go.uber.org/zap/zapio.Writer).Close + - (*go.uber.org/zap/zapio.Writer).Sync + - (*go.uber.org/zap/zapio.Writer).Write + - io.WriteString(*go.uber.org/zap/zapio.Writer) + - io.WriteString(fmt.State) + govet: + enable: + - nilness + - reflectvaluecompare + - sortslice + - unusedwrite + exclusions: + generated: lax + rules: + - linters: + - revive + text: 'unused-parameter: parameter \S+ seems to be unused, consider removing or renaming it as _' + - linters: + - revive + text: 'empty-block: this block is empty, you can remove it' + - 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' +formatters: + enable: + - gofumpt + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ From cfa0f88aa7f3bb7b725bf2da83e11d817f164d6c Mon Sep 17 00:00:00 2001 From: junya koyama Date: Thu, 18 Sep 2025 00:09:46 +0900 Subject: [PATCH 2/8] add acomment, move a blocks. Signed-off-by: junya koyama --- .golangci.yml | 76 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 54c606e55..3cb22379d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,57 +1,83 @@ 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. default: none enable: + # golangci-lint defaults: - errcheck - govet - ineffassign - - nolintlint - - revive - - staticcheck + - staticcheck # gosimple has been merged inside the staticcheck. - unused + + # Our own extras: + - 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 + - (*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) + + # Writing a plain string to a fmt.State cannot fail. - io.WriteString(fmt.State) - govet: - enable: - - nilness - - reflectvaluecompare - - sortslice - - unusedwrite 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 + rules: - - linters: - - revive + # 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 _' - - linters: - - revive + + # 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' - - linters: - - errcheck + + # 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 + 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 -formatters: - enable: - - gofumpt - exclusions: - generated: lax - paths: - - third_party$ - - builtin$ - - examples$ From 9cea28cdb867ef981ef0034e74f024bb418f545c Mon Sep 17 00:00:00 2001 From: junya koyama Date: Thu, 18 Sep 2025 00:13:21 +0900 Subject: [PATCH 3/8] Bump golangci-lint to v7 Signed-off-by: junya koyama --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 1a692cad2..0f9f705df 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -59,7 +59,7 @@ jobs: go-version: 1.23.x cache: false # managed by golangci-lint - - uses: golangci/golangci-lint-action@v6 + - uses: golangci/golangci-lint-action@v7 name: Install golangci-lint with: version: latest From 1cad6c8596d032da6c9a500911bf2c1f07c73058 Mon Sep 17 00:00:00 2001 From: junya koyama Date: Thu, 18 Sep 2025 00:18:59 +0900 Subject: [PATCH 4/8] zapcore/field_test.go: fix QF1003 Signed-off-by: junya koyama --- zapcore/field_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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)) From af56279f5b8eafa0e4f24efd0552c68ec8854fbb Mon Sep 17 00:00:00 2001 From: junya koyama Date: Thu, 18 Sep 2025 00:26:12 +0900 Subject: [PATCH 5/8] zapcore/lazy_with.go: fix QF1008 Signed-off-by: junya koyama --- zapcore/lazy_with.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zapcore/lazy_with.go b/zapcore/lazy_with.go index 05288d6a8..76cedd4b7 100644 --- a/zapcore/lazy_with.go +++ b/zapcore/lazy_with.go @@ -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) }) } From ae09d6aabd09ff61380dac89d5743ede277779e0 Mon Sep 17 00:00:00 2001 From: junya koyama Date: Thu, 18 Sep 2025 00:28:13 +0900 Subject: [PATCH 6/8] zaptest/logger_test.go: fix QF1008 Signed-off-by: junya koyama --- zaptest/logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { From 20725ad14df9ca64251bf069fa92d1325b6f288f Mon Sep 17 00:00:00 2001 From: junya koyama Date: Thu, 18 Sep 2025 00:32:29 +0900 Subject: [PATCH 7/8] Bump golangci-lint to v8 Signed-off-by: junya koyama --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0f9f705df..a92c62bef 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -59,7 +59,7 @@ jobs: go-version: 1.23.x cache: false # managed by golangci-lint - - uses: golangci/golangci-lint-action@v7 + - uses: golangci/golangci-lint-action@v8 name: Install golangci-lint with: version: latest From 4d00235dbaf60d90b8c186bff09b83b01e50e5a2 Mon Sep 17 00:00:00 2001 From: junya koyama Date: Mon, 17 Nov 2025 22:46:41 +0900 Subject: [PATCH 8/8] Fix gofumpt problems in lazyWithCore Signed-off-by: junya koyama --- zapcore/lazy_with.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zapcore/lazy_with.go b/zapcore/lazy_with.go index c6b172ab5..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 }