From f69247ff2478057ddbbc6692fc96ff6520b6a8c1 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 25 Aug 2023 15:28:13 -0500 Subject: [PATCH] build: Add errorlint linter. This adds the errorlint linter to the list of linters and addresses a few false positives it complains about. --- .golangci.yml | 1 + dcrutil/wif_test.go | 3 ++- wire/error.go | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index d6a430b9da..55b6717152 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,6 +12,7 @@ linters: - dupword - durationcheck - errchkjson + - errorlint - exportloopref - gofmt - goimports diff --git a/dcrutil/wif_test.go b/dcrutil/wif_test.go index e8fcc65b5b..01a717c991 100644 --- a/dcrutil/wif_test.go +++ b/dcrutil/wif_test.go @@ -1,5 +1,5 @@ // Copyright (c) 2013, 2014 The btcsuite developers -// Copyright (c) 2015-2021 The Decred developers +// Copyright (c) 2015-2023 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -38,6 +38,7 @@ func TestWIF(t *testing.T) { if (err == nil) != (target == nil) { return false } + // nolint: errorlint return err == target || (err != nil && err.Error() == target.Error()) } diff --git a/wire/error.go b/wire/error.go index 9f6ebd2b31..d21279220d 100644 --- a/wire/error.go +++ b/wire/error.go @@ -189,6 +189,7 @@ func (e ErrorCode) Error() string { // - The target is a *MessageError and the error codes match // - The target is an ErrorCode and it the error codes match func (e ErrorCode) Is(target error) bool { + // nolint: errorlint switch target := target.(type) { case *MessageError: return e == target.ErrorCode @@ -232,6 +233,7 @@ func messageError(funcName string, c ErrorCode, desc string) *MessageError { // - The target is a *MessageError and the error codes match // - The target is an ErrorCode and it the error codes match func (m *MessageError) Is(target error) bool { + // nolint: errorlint switch target := target.(type) { case *MessageError: return m.ErrorCode == target.ErrorCode