diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 297bb973ce..d6a996bade 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7.0.0 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. version: latest diff --git a/.golangci.yml b/.golangci.yml index b01d130cf6..0ba66d6789 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,11 @@ -# Golang CI pipeline configuration +version: "2" +formatters: + enable: + - gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false] + - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] + - gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true] + - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true] + linters: # Run golangci-lint linters to see the list of all linters # Please keep them sorted alphabetically @@ -22,21 +29,16 @@ linters: - exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. [auto-fix] - fatcontext # Detects nested contexts in loops and function literals. [auto-fix] - forbidigo # Forbids identifiers [fast: true, auto-fix: false] - - gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false] - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false] - gochecksumtype # Run exhaustiveness checks on Go "sum types" [fast: false, auto-fix: false] - goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] - gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false] - gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] - - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] - - gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true] - goheader # Checks is file header matches to pattern [fast: true, auto-fix: false] - - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true] - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false] - gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false] - goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false] - gosec #(gas): Inspects source code for security problems [fast: false, auto-fix: false] - - gosimple #(megacheck): Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false] - gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase [fast: false, auto-fix: false] - govet #(vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false] - grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false] @@ -67,14 +69,12 @@ linters: - sloglint # ensure consistent code style when using log/slog [fast: false, auto-fix: false] - sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false] - staticcheck #(megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false] - - stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false] - tagalign # check that struct tags are well aligned [fast: true, auto-fix: true] - tagliatelle # Checks the struct tags. [fast: true, auto-fix: false] - testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false] - testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false] - thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false] - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false] - - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false] - unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false] - unused #(megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast: true, auto-fix: false] @@ -104,19 +104,24 @@ linters: - nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false] - varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false] -linters-settings: - goconst: - min-len: 5 - gosec: - excludes: - - G115 + settings: + goconst: + min-len: 5 + gosec: + excludes: + - G115 + revive: + rules: + - name: exported + disabled: true -issues: - exclude-rules: - - path: _test\.go - linters: - - stylecheck - - gosec + exclusions: + rules: + - path: _test\.go + linters: + - stylecheck + - gosec +issues: max-issues-per-linter: 0 max-same-issues: 0 diff --git a/internal/datasource/search.go b/internal/datasource/search.go index ec1543c81a..ebe96c35ab 100644 --- a/internal/datasource/search.go +++ b/internal/datasource/search.go @@ -9,7 +9,7 @@ import ( // FindExact finds the first element in 'slice' matching the condition defined by 'finder'. // It returns the first matching element and an error if either no match is found or multiple matches are found. -func FindExact[T any](slice []T, finder func(T) bool, searchName string) (T, error) { //nolint:ireturn +func FindExact[T any](slice []T, finder func(T) bool, searchName string) (T, error) { //nolint var found T var foundFlag bool diff --git a/internal/services/container/testfuncs/checks.go b/internal/services/container/testfuncs/checks.go index c0ddb7eb5e..3c8828277d 100644 --- a/internal/services/container/testfuncs/checks.go +++ b/internal/services/container/testfuncs/checks.go @@ -77,7 +77,7 @@ func TestConfigContainerNamespace(tt *acctest.TestTools, n string) resource.Test return fmt.Errorf("could not pull image: %w", err) } - defer out.Close() + defer out.Close() //nolint: errcheck buffIOReader := bufio.NewReader(out) @@ -110,7 +110,7 @@ func TestConfigContainerNamespace(tt *acctest.TestTools, n string) resource.Test return fmt.Errorf("could not push image: %w", err) } - defer pusher.Close() + defer pusher.Close() //nolint: errcheck buffIOReader = bufio.NewReader(pusher) diff --git a/internal/services/domain/registration.go b/internal/services/domain/registration.go index f2ca2d61f6..039812a06c 100644 --- a/internal/services/domain/registration.go +++ b/internal/services/domain/registration.go @@ -518,15 +518,9 @@ func resourceRegistrationsRead(ctx context.Context, d *schema.ResourceData, m in computedAdministrativeContact := flattenContact(firstResp.AdministrativeContact) computedTechnicalContact := flattenContact(firstResp.TechnicalContact) - computedAutoRenew := false - if firstResp.AutoRenewStatus == domain.DomainFeatureStatusEnabled { - computedAutoRenew = true - } + computedAutoRenew := firstResp.AutoRenewStatus == domain.DomainFeatureStatusEnabled - computedDnssec := false - if firstResp.Dnssec.Status == domain.DomainFeatureStatusEnabled { - computedDnssec = true - } + computedDnssec := firstResp.Dnssec.Status == domain.DomainFeatureStatusEnabled var computedDSRecord []interface{} if firstResp.Dnssec != nil { diff --git a/internal/services/function/helpers.go b/internal/services/function/helpers.go index bb651c6308..e8fc1b8c6e 100644 --- a/internal/services/function/helpers.go +++ b/internal/services/function/helpers.go @@ -66,11 +66,11 @@ func functionUpload(ctx context.Context, m interface{}, functionAPI *function.AP return fmt.Errorf("failed to fetch upload url: %w", err) } - zip, err := os.Open(zipFile) + zip, err := os.Open(zipFile) //nolint:gosec if err != nil { return fmt.Errorf("failed to read zip file: %w", err) } - defer zip.Close() + defer zip.Close() //nolint: errcheck req, err := http.NewRequest(http.MethodPut, uploadURL.URL, zip) if err != nil { @@ -92,7 +92,7 @@ func functionUpload(ctx context.Context, m interface{}, functionAPI *function.AP if err != nil { return fmt.Errorf("failed to send request: %w", err) } - defer resp.Body.Close() + defer resp.Body.Close() //nolint: errcheck respDump, err := httputil.DumpResponse(resp, true) if err != nil { diff --git a/internal/services/instance/instancehelpers/block.go b/internal/services/instance/instancehelpers/block.go index 43913f12aa..7456afb1c0 100644 --- a/internal/services/instance/instancehelpers/block.go +++ b/internal/services/instance/instancehelpers/block.go @@ -125,7 +125,7 @@ type UnknownSnapshot struct { } func (api *BlockAndInstanceAPI) GetUnknownVolume(req *GetUnknownVolumeRequest, opts ...scw.RequestOption) (*UnknownVolume, error) { - getVolumeResponse, err := api.API.GetVolume(&instance.GetVolumeRequest{ + getVolumeResponse, err := api.GetVolume(&instance.GetVolumeRequest{ Zone: req.Zone, VolumeID: req.VolumeID, }, opts...) @@ -194,7 +194,7 @@ func (api *BlockAndInstanceAPI) ResizeUnknownVolume(req *ResizeUnknownVolumeRequ Size: req.Size, }, opts...) } else { - _, err = api.API.UpdateVolume(&instance.UpdateVolumeRequest{ + _, err = api.UpdateVolume(&instance.UpdateVolumeRequest{ Zone: req.Zone, VolumeID: req.VolumeID, Size: req.Size, @@ -219,7 +219,7 @@ func (api *BlockAndInstanceAPI) DeleteUnknownVolume(req *DeleteUnknownVolumeRequ VolumeID: req.VolumeID, }, opts...) } else { - err = api.API.DeleteVolume(&instance.DeleteVolumeRequest{ + err = api.DeleteVolume(&instance.DeleteVolumeRequest{ Zone: req.Zone, VolumeID: req.VolumeID, }, opts...) diff --git a/internal/services/instance/testfuncs/sweep.go b/internal/services/instance/testfuncs/sweep.go index 0d29fa809d..8f6acd5496 100644 --- a/internal/services/instance/testfuncs/sweep.go +++ b/internal/services/instance/testfuncs/sweep.go @@ -112,7 +112,8 @@ func testSweepServer(_ string) error { } for _, srv := range listServers.Servers { - if srv.State == instanceSDK.ServerStateStopped || srv.State == instanceSDK.ServerStateStoppedInPlace { + switch srv.State { + case instanceSDK.ServerStateStopped, instanceSDK.ServerStateStoppedInPlace: err := instanceAPI.DeleteServer(&instanceSDK.DeleteServerRequest{ Zone: zone, ServerID: srv.ID, @@ -120,7 +121,7 @@ func testSweepServer(_ string) error { if err != nil { return fmt.Errorf("error deleting server in sweeper: %w", err) } - } else if srv.State == instanceSDK.ServerStateRunning { + case instanceSDK.ServerStateRunning: _, err := instanceAPI.ServerAction(&instanceSDK.ServerActionRequest{ Zone: zone, ServerID: srv.ID, diff --git a/internal/services/iot/helpers_iot.go b/internal/services/iot/helpers_iot.go index 75c3a35bcd..cc437e0393 100644 --- a/internal/services/iot/helpers_iot.go +++ b/internal/services/iot/helpers_iot.go @@ -87,7 +87,7 @@ func computeIotHubMQTTCa(ctx context.Context, mqttCaURL string, m interface{}) ( return "", err } - defer mqttCa.Body.Close() + defer mqttCa.Body.Close() //nolint: errcheck resp, _ := io.ReadAll(mqttCa.Body) return string(resp), nil diff --git a/internal/services/k8s/cluster.go b/internal/services/k8s/cluster.go index 2cf5421565..b9f88cb74f 100644 --- a/internal/services/k8s/cluster.go +++ b/internal/services/k8s/cluster.go @@ -446,7 +446,7 @@ func ResourceK8SClusterCreate(ctx context.Context, d *schema.ResourceData, m int // check if either all or none of the auto upgrade attribute are set. // if one auto upgrade attribute is set, they all must be set. // if none is set, auto upgrade attributes will be computed. - if !(okAutoUpgradeDay && okAutoUpgradeStartHour) { + if !okAutoUpgradeDay || !okAutoUpgradeStartHour { return append(diag.FromErr(errors.New("all field or zero field of auto_upgrade must be set")), diags...) } } diff --git a/internal/services/registry/testfuncs/checks.go b/internal/services/registry/testfuncs/checks.go index 30ddb0c337..2f56478b64 100644 --- a/internal/services/registry/testfuncs/checks.go +++ b/internal/services/registry/testfuncs/checks.go @@ -56,7 +56,7 @@ func PushImageToRegistry(tt *acctest.TestTools, registryEndpoint string, tagName if err != nil { return fmt.Errorf("could not pull image: %w", err) } - defer out.Close() + defer out.Close() //nolint: errcheck buffIOReader := bufio.NewReader(out) @@ -87,7 +87,7 @@ func PushImageToRegistry(tt *acctest.TestTools, registryEndpoint string, tagName if err != nil { return fmt.Errorf("could not push image: %w", err) } - defer pusher.Close() + defer pusher.Close() //nolint: errcheck buffIOReader = bufio.NewReader(pusher) diff --git a/internal/services/vpc/types.go b/internal/services/vpc/types.go index 0d2b8fc833..7f8c876ce1 100644 --- a/internal/services/vpc/types.go +++ b/internal/services/vpc/types.go @@ -83,7 +83,7 @@ func flattenAndSortIPNetSubnets(subnets []scw.IPNet) (interface{}, interface{}) flatIpv6Subnets = append(flatIpv6Subnets, map[string]interface{}{ "subnet": sub, "address": s.IP.String(), - "subnet_mask": maskHexToDottedDecimal(s.IPNet.Mask), + "subnet_mask": maskHexToDottedDecimal(s.Mask), "prefix_length": getPrefixLength(s.Mask), }) } diff --git a/internal/transport/retry.go b/internal/transport/retry.go index 38a313a51b..45e5176068 100644 --- a/internal/transport/retry.go +++ b/internal/transport/retry.go @@ -108,10 +108,10 @@ func (c *RetryableTransport) RoundTrip(r *http.Request) (*http.Response, error) return io.NopCloser(bytes.NewReader(b)), err } - return c.Client.Do(req) + return c.Do(req) } -func RetryOnTransientStateError[T any, U any](action func() (T, error), waiter func() (U, error)) (T, error) { //nolint:ireturn +func RetryOnTransientStateError[T any, U any](action func() (T, error), waiter func() (U, error)) (T, error) { //nolint t, err := action() var transientStateError *scw.TransientStateError