Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@v8
name: Install golangci-lint
with:
version: latest
Expand Down
116 changes: 61 additions & 55 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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'
7 changes: 4 additions & 3 deletions zapcore/field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion zapcore/lazy_with.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion zaptest/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down