From 3936e44bce1000b78d9317291bd3eefa9555a54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Svantesson?= Date: Tue, 4 Jun 2024 13:04:39 +0200 Subject: [PATCH] fix: linting related to jenkins-x/jx#8670 --- .golangci.yml | 48 +++++++++++++---------------- scm/client.go | 4 +-- scm/const.go | 2 +- scm/driver/azure/webhook.go | 3 +- scm/driver/fake/repo.go | 2 +- scm/driver/gitea/webhook.go | 2 +- scm/example_test.go | 2 +- scm/transport/oauth2/oauth2_test.go | 2 +- 8 files changed, 30 insertions(+), 35 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index eddc0e830..ea14ecaa8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,14 +1,16 @@ linters-settings: depguard: - list-type: blacklist - packages: - - github.com/jenkins-x/jx/v2/pkg/log/ - - github.com/satori/go.uuid - - github.com/pborman/uuid - packages-with-error-message: - - github.com/jenkins-x/jx/v2/pkg/log/: "use jenkins-x/jx-logging instead" - - github.com/satori/go.uuid: "use github.com/google/uuid instead" - - github.com/pborman/uuid: "use github.com/google/uuid instead" + rules: + # Name of a rule. + Main: + list-mode: lax + deny: + - pkg: github.com/jenkins-x/jx/v2/pkg/log/ + desc: "use jenkins-x/jx-logging instead" + - pkg: github.com/satori/go.uuid + desc: "use github.com/google/uuid instead" + - pkg: github.com/pborman/uuid + desc: "use github.com/google/uuid instead" dupl: threshold: 100 exhaustive: @@ -37,17 +39,14 @@ linters-settings: gocyclo: min-complexity: 15 goimports: {} - golint: - min-confidence: 0 + revive: + confidence: 0 gofmt: simplify: true - gomnd: - settings: - mnd: - # don't include the "operation" and "assign" - checks: [argument, case, condition, return] + mnd: + # don't include the "operation" and "assign" + checks: [argument, case, condition, return] govet: - check-shadowing: true settings: printf: funcs: @@ -58,11 +57,8 @@ linters-settings: - (github.com/jenkins-x/jx-logging/v3/pkg/log/Logger()).Fatalf lll: line-length: 140 - maligned: - suggest-new: true misspell: {} nolintlint: - allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) allow-unused: false # report any unused nolint directives require-explanation: false # don't require an explanation for nolint directives require-specific: false # don't require nolint directives to be specific about which linter is being skipped @@ -102,17 +98,17 @@ issues: - linters: - gocritic text: "unnecessaryDefer:" + - path: scm/driver/ # The drivers mostly implement interfaces and often the methods don't need all parameters + text: "unused-parameter" + linters: + - revive exclude: - 'shadow: declaration of "err" shadows declaration at' max-same-issues: 0 + exclude-dirs: + - cmd/docs run: timeout: 30m - skip-dirs: - - cmd/docs # golangci.com configuration # https://github.com/golangci/golangci/wiki/Configuration -service: - golangci-lint-version: 1.42.x # use the fixed version to not introduce new linters unexpectedly - prepare: - - echo "here I can run custom commands, but no preparation needed for this repo" diff --git a/scm/client.go b/scm/client.go index 500a0835e..d6b152a9c 100644 --- a/scm/client.go +++ b/scm/client.go @@ -7,10 +7,8 @@ package scm import ( "context" "errors" - "io" "net/http" - "net/url" "strconv" "strings" @@ -182,6 +180,8 @@ func (c *Client) Do(ctx context.Context, in *Request) (*Response, error) { if client == nil { client = http.DefaultClient } + // The callers of this method should do the closing + //nolint:bodyclose res, err := client.Do(req) if err != nil { return nil, err diff --git a/scm/const.go b/scm/const.go index 9ac83b17d..3f1db75fa 100644 --- a/scm/const.go +++ b/scm/const.go @@ -157,7 +157,7 @@ func (a Action) String() (s string) { case ActionCompleted: return "completed" default: - return + return "" } } diff --git a/scm/driver/azure/webhook.go b/scm/driver/azure/webhook.go index d2e6f0daa..7eaabe09c 100644 --- a/scm/driver/azure/webhook.go +++ b/scm/driver/azure/webhook.go @@ -93,9 +93,8 @@ func getIssueCommentAction(src *issueCommentPullRequestHook) scm.Action { return scm.ActionDelete } else if src.Resource.Comment.PublishedDate.Equal(src.Resource.Comment.LastUpdatedDate) { return scm.ActionCreate - } else { - return scm.ActionEdited } + return scm.ActionEdited } func convertPushHook(src *pushHook) *scm.PushHook { diff --git a/scm/driver/fake/repo.go b/scm/driver/fake/repo.go index e76357e1c..c8b688075 100644 --- a/scm/driver/fake/repo.go +++ b/scm/driver/fake/repo.go @@ -179,8 +179,8 @@ func (s *repositoryService) ListHooks(ctx context.Context, fullName string, opts } func (s *repositoryService) CreateHook(ctx context.Context, fullName string, input *scm.HookInput) (*scm.Hook, *scm.Response, error) { - /* #nosec */ hook := &scm.Hook{ + //nolint:gosec ID: fmt.Sprintf("%d", rand.Int()), Name: input.Name, Target: input.Target, diff --git a/scm/driver/gitea/webhook.go b/scm/driver/gitea/webhook.go index 763c7578b..f0f20a50c 100644 --- a/scm/driver/gitea/webhook.go +++ b/scm/driver/gitea/webhook.go @@ -424,6 +424,6 @@ func convertAction(src string) (action scm.Action) { case "reviewed": return scm.ActionSubmitted default: - return + return 0 } } diff --git a/scm/example_test.go b/scm/example_test.go index 2642837f5..eb2b31403 100644 --- a/scm/example_test.go +++ b/scm/example_test.go @@ -673,7 +673,7 @@ func ExamplePullRequest_merge() { func ExampleWebhook() { client := github.NewDefault() - secret := func(webhook scm.Webhook) (string, error) { + secret := func(_ scm.Webhook) (string, error) { return "topsecret", nil } diff --git a/scm/transport/oauth2/oauth2_test.go b/scm/transport/oauth2/oauth2_test.go index df719c326..435659e1c 100644 --- a/scm/transport/oauth2/oauth2_test.go +++ b/scm/transport/oauth2/oauth2_test.go @@ -108,6 +108,6 @@ type mockErrorSource struct { err error } -func (s mockErrorSource) Token(ctx context.Context) (*scm.Token, error) { +func (s mockErrorSource) Token(_ context.Context) (*scm.Token, error) { return nil, s.err }