Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 25 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion internal/datasource/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/services/container/testfuncs/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
10 changes: 2 additions & 8 deletions internal/services/domain/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions internal/services/function/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions internal/services/instance/instancehelpers/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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,
Expand All @@ -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...)
Expand Down
5 changes: 3 additions & 2 deletions internal/services/instance/testfuncs/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ 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,
})
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,
Expand Down
2 changes: 1 addition & 1 deletion internal/services/iot/helpers_iot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/services/k8s/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/services/registry/testfuncs/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion internal/services/vpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/transport/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading