From 03870e56504aea05e56217cf7fb7b0010d712b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20K=C3=B6ser?= Date: Thu, 24 Oct 2024 15:07:36 +0200 Subject: [PATCH] ci(lint): update and fix golangci-lint (#874) --- .github/workflows/ci.yml | 2 +- .golangci.yaml | 6 +++--- notify_test.go | 20 +++----------------- send_test.go | 3 --- service/webpush/webpush_test.go | 9 ++++----- use_test.go | 3 --- 6 files changed, 11 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f481a3..10611a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,4 +31,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.59 + version: v1.61 diff --git a/.golangci.yaml b/.golangci.yaml index 5b16256..a861a2c 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,7 +1,7 @@ # This code is licensed under the terms of the MIT license https://opensource.org/license/mit # Copyright (c) 2021 Marat Reymers -## Golden config for golangci-lint v1.59.1 +## Golden config for golangci-lint v1.61.0 # # This is the best config for golangci-lint based on my experience and opinion. # It is very strict, but not extremely strict. @@ -225,14 +225,13 @@ linters: - bidichk # checks for dangerous unicode character sequences - bodyclose # checks whether HTTP response body is closed successfully - canonicalheader # checks whether net/http.Header uses canonical header - - copyloopvar # detects places where loop variables are copied + - copyloopvar # detects places where loop variables are copied (Go 1.22+) - cyclop # checks function and package cyclomatic complexity - dupl # tool for code clone detection - durationcheck # checks for two durations multiplied together - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 - exhaustive # checks exhaustiveness of enum switch statements - - exportloopref # checks for pointers to enclosing loop variables - fatcontext # detects nested contexts in loops - forbidigo # forbids identifiers - funlen # tool for detection of long functions @@ -312,6 +311,7 @@ linters: #- err113 # [too strict] checks the errors handling expressions #- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted #- execinquery # [deprecated] checks query string in Query function which reads your Go src files and warning it finds + #- exportloopref # [not necessary from Go 1.22] checks for pointers to enclosing loop variables #- forcetypeassert # [replaced by errcheck] finds forced type assertions #- gofmt # [replaced by goimports] checks whether code was gofmt-ed #- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed diff --git a/notify_test.go b/notify_test.go index c04efca..fbf0f62 100644 --- a/notify_test.go +++ b/notify_test.go @@ -13,9 +13,7 @@ func TestNew(t *testing.T) { t.Parallel() n1 := New() - if n1 == nil { - t.Fatal("New() returned nil") - } + if n1.Disabled { t.Fatal("New() returned disabled Notifier") } @@ -56,9 +54,7 @@ func TestDefault(t *testing.T) { t.Parallel() n := Default() - if n == nil { - t.Fatal("Default() returned nil") - } + if n.Disabled { t.Fatal("Default() returned disabled Notifier") } @@ -71,24 +67,14 @@ func TestDefault(t *testing.T) { func TestNewWithServices(t *testing.T) { t.Parallel() - n1 := NewWithServices() - if n1 == nil { - t.Fatal("NewWithServices() returned nil") - } - n2 := NewWithServices(nil) - if n2 == nil { - t.Fatal("NewWithServices(nil) returned nil") - } + if len(n2.notifiers) != 0 { t.Error("NewWithServices(nil) did not return empty Notifier") } mailService := mail.New("", "") n3 := NewWithServices(mailService) - if n3 == nil { - t.Fatal("NewWithServices(mail.New()) returned nil") - } if len(n3.notifiers) != 1 { t.Errorf("NewWithServices(mail.New()) was expected to have 1 notifier but had %d", len(n3.notifiers)) } else { diff --git a/send_test.go b/send_test.go index 3152ed9..5724ac8 100644 --- a/send_test.go +++ b/send_test.go @@ -11,9 +11,6 @@ func TestNotifySend(t *testing.T) { t.Parallel() n := New() - if n == nil { - t.Fatal("New() returned nil") - } if n.Disabled { t.Fatal("New() returned disabled Notifier") } diff --git a/service/webpush/webpush_test.go b/service/webpush/webpush_test.go index 2a3d1bd..cbb4217 100644 --- a/service/webpush/webpush_test.go +++ b/service/webpush/webpush_test.go @@ -615,7 +615,6 @@ func Test_payloadFromContext(t *testing.T) { t.Parallel() type args struct { - ctx context.Context subject string message string data map[string]interface{} @@ -629,7 +628,6 @@ func Test_payloadFromContext(t *testing.T) { { name: "Payload with only subject and message", args: args{ - ctx: context.Background(), subject: "test", message: "test", }, @@ -638,7 +636,6 @@ func Test_payloadFromContext(t *testing.T) { { name: "Payload with subject, message and data", args: args{ - ctx: context.Background(), subject: "test", message: "test", data: map[string]interface{}{ @@ -657,11 +654,13 @@ func Test_payloadFromContext(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() + ctx := context.Background() + if tt.args.data != nil { - tt.args.ctx = WithData(tt.args.ctx, tt.args.data) + ctx = WithData(ctx, tt.args.data) } - got, err := payloadFromContext(tt.args.ctx, tt.args.subject, tt.args.message) + got, err := payloadFromContext(ctx, tt.args.subject, tt.args.message) if (err != nil) != tt.wantErr { t.Errorf("payloadFromContext() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/use_test.go b/use_test.go index 01e4b6b..6311439 100644 --- a/use_test.go +++ b/use_test.go @@ -10,9 +10,6 @@ func TestUseServices(t *testing.T) { t.Parallel() n := New() - if n == nil { - t.Fatal("New() returned nil") - } if len(n.notifiers) != 0 { t.Fatalf("Expected len(n.notifiers) == 0, got %d", len(n.notifiers)) }