From 8876b68a604b9b22675caef07593da22cb529452 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 13 Feb 2024 14:12:04 +0100 Subject: [PATCH] golangci-lint: add hints for error wrapping Wrapping errors may or may not be the right thing to do (see https://go.dev/blog/go1.13-errors#whether-to-wrap and the discussion in https://github.com/kubernetes/kubernetes/issues/123234). But developers should at least think about it, so let's emit linter hints for it: the golangci-lint config by default enables it for go-errorlint, just not the linter itself, so we just need to add it for the "hints" config. Direct error comparisons and assertions also get checked. Those are typically something that should be replaced by errors.Is and errors.As, but as the existing code often doesn't do that, let's also treat those as just hints. --- hack/golangci-hints.yaml | 1 + hack/golangci.yaml.in | 3 +++ 2 files changed, 4 insertions(+) diff --git a/hack/golangci-hints.yaml b/hack/golangci-hints.yaml index 0ee2ba794e0..cd98978d137 100644 --- a/hack/golangci-hints.yaml +++ b/hack/golangci-hints.yaml @@ -84,6 +84,7 @@ linters: - ginkgolinter - gocritic - govet + - errorlint - ineffassign - logcheck - revive diff --git a/hack/golangci.yaml.in b/hack/golangci.yaml.in index 0b556cf5cf4..7094669400e 100644 --- a/hack/golangci.yaml.in +++ b/hack/golangci.yaml.in @@ -140,6 +140,9 @@ linters: - ginkgolinter - gocritic - govet + {{- if .Hints}} + - errorlint + {{- end}} - ineffassign - logcheck - revive