From b34ac774569761b6d36b8f0d945f96f2a449c7ba Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 4 Aug 2023 13:33:12 +0200 Subject: [PATCH] update linter config and fix issues Selecting linters in the workflow file has the disadvantage that a manual "golangci-lint run" invocation uses different settings. It's better to do it in a configuration file. Several of the selected linters were deprecated and thus get removed: WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. Some issues were reported with this configuration by golangci-lint 1.52.2 and get fixed. --- .github/workflows/lint.yaml | 19 ------------------- .golangci.yaml | 20 ++++++++++++++++++++ example/main.go | 2 ++ internal/types/objectref.go | 2 ++ zapr.go | 6 +++--- zapr_test.go | 2 +- 6 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 .golangci.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index d76ae31..ba697de 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -21,22 +21,3 @@ jobs: args: -v --max-same-issues 10 - --disable-all - --exclude-use-default=false - -E asciicheck - -E deadcode - -E errcheck - -E forcetypeassert - -E gocritic - -E gofmt - -E goimports - -E gosimple - -E govet - -E ineffassign - -E misspell - -E revive - -E staticcheck - -E structcheck - -E typecheck - -E unused - -E varcheck diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..64246c5 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,20 @@ +issues: + exclude-use-default: false + +linters: + disable-all: true + enable: + - asciicheck + - errcheck + - forcetypeassert + - gocritic + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - misspell + - revive + - staticcheck + - typecheck + - unused diff --git a/example/main.go b/example/main.go index 31eb1f3..aece6d7 100644 --- a/example/main.go +++ b/example/main.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// This example shows how to instantiate a zap logger and what output +// looks like. package main import ( diff --git a/internal/types/objectref.go b/internal/types/objectref.go index 34bb883..85850f5 100644 --- a/internal/types/objectref.go +++ b/internal/types/objectref.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package types holds a copy of the ObjectRef type from klog for +// use in the example. package types import ( diff --git a/zapr.go b/zapr.go index 8bb7fce..1dadd0d 100644 --- a/zapr.go +++ b/zapr.go @@ -31,14 +31,14 @@ limitations under the License. // Package zapr defines an implementation of the github.com/go-logr/logr // interfaces built on top of Zap (go.uber.org/zap). // -// Usage +// # Usage // // A new logr.Logger can be constructed from an existing zap.Logger using // the NewLogger function: // -// log := zapr.NewLogger(someZapLogger) +// log := zapr.NewLogger(someZapLogger) // -// Implementation Details +// # Implementation Details // // For the most part, concepts in Zap correspond directly with those in // logr. diff --git a/zapr_test.go b/zapr_test.go index 7642a2d..1d870e4 100644 --- a/zapr_test.go +++ b/zapr_test.go @@ -45,7 +45,7 @@ func fixedTimeEncoder(_ time.Time, enc zapcore.PrimitiveArrayEncoder) { // discard is a replacement for io.Discard, needed for Go 1.14. type discard struct{} -func (d discard) Write(p []byte) (n int, err error) { return n, nil } +func (d discard) Write(_ []byte) (int, error) { return 0, nil } type marshaler struct { msg string