Skip to content

Commit fadbd55

Browse files
authored
chore: migrate to golangci-lint v2 (#3001)
1 parent f5d4aa6 commit fadbd55

File tree

13 files changed

+47
-47
lines changed

13 files changed

+47
-47
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515
- name: golangci-lint
16-
uses: golangci/golangci-lint-action@v6
16+
uses: golangci/golangci-lint-action@v7.0.0
1717
with:
1818
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
1919
version: latest

.golangci.yml

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
# Golang CI pipeline configuration
1+
version: "2"
2+
formatters:
3+
enable:
4+
- gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false]
5+
- 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]
6+
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
7+
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
8+
29
linters:
310
# Run golangci-lint linters to see the list of all linters
411
# Please keep them sorted alphabetically
@@ -22,21 +29,16 @@ linters:
2229
- exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. [auto-fix]
2330
- fatcontext # Detects nested contexts in loops and function literals. [auto-fix]
2431
- forbidigo # Forbids identifiers [fast: true, auto-fix: false]
25-
- gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false]
2632
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false]
2733
- gochecksumtype # Run exhaustiveness checks on Go "sum types" [fast: false, auto-fix: false]
2834
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
2935
- gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false]
3036
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
31-
- 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]
32-
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
3337
- goheader # Checks is file header matches to pattern [fast: true, auto-fix: false]
34-
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
3538
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false]
3639
- 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]
3740
- goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false]
3841
- gosec #(gas): Inspects source code for security problems [fast: false, auto-fix: false]
39-
- gosimple #(megacheck): Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]
4042
- gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase [fast: false, auto-fix: false]
4143
- 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]
4244
- grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false]
@@ -67,14 +69,12 @@ linters:
6769
- sloglint # ensure consistent code style when using log/slog [fast: false, auto-fix: false]
6870
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false]
6971
- staticcheck #(megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
70-
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
7172
- tagalign # check that struct tags are well aligned [fast: true, auto-fix: true]
7273
- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
7374
- testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false]
7475
- testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
7576
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
7677
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false]
77-
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false]
7878
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
7979
- unused #(megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
8080
- 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:
104104
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
105105
- varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
106106

107-
linters-settings:
108-
goconst:
109-
min-len: 5
110-
gosec:
111-
excludes:
112-
- G115
107+
settings:
108+
goconst:
109+
min-len: 5
110+
gosec:
111+
excludes:
112+
- G115
113+
revive:
114+
rules:
115+
- name: exported
116+
disabled: true
113117

114-
issues:
115-
exclude-rules:
116-
- path: _test\.go
117-
linters:
118-
- stylecheck
119-
- gosec
118+
exclusions:
119+
rules:
120+
- path: _test\.go
121+
linters:
122+
- stylecheck
123+
- gosec
120124

125+
issues:
121126
max-issues-per-linter: 0
122127
max-same-issues: 0

internal/datasource/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
// FindExact finds the first element in 'slice' matching the condition defined by 'finder'.
1111
// It returns the first matching element and an error if either no match is found or multiple matches are found.
12-
func FindExact[T any](slice []T, finder func(T) bool, searchName string) (T, error) { //nolint:ireturn
12+
func FindExact[T any](slice []T, finder func(T) bool, searchName string) (T, error) { //nolint
1313
var found T
1414

1515
var foundFlag bool

internal/services/container/testfuncs/checks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestConfigContainerNamespace(tt *acctest.TestTools, n string) resource.Test
7777
return fmt.Errorf("could not pull image: %w", err)
7878
}
7979

80-
defer out.Close()
80+
defer out.Close() //nolint: errcheck
8181

8282
buffIOReader := bufio.NewReader(out)
8383

@@ -110,7 +110,7 @@ func TestConfigContainerNamespace(tt *acctest.TestTools, n string) resource.Test
110110
return fmt.Errorf("could not push image: %w", err)
111111
}
112112

113-
defer pusher.Close()
113+
defer pusher.Close() //nolint: errcheck
114114

115115
buffIOReader = bufio.NewReader(pusher)
116116

internal/services/domain/registration.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,15 +518,9 @@ func resourceRegistrationsRead(ctx context.Context, d *schema.ResourceData, m in
518518
computedAdministrativeContact := flattenContact(firstResp.AdministrativeContact)
519519
computedTechnicalContact := flattenContact(firstResp.TechnicalContact)
520520

521-
computedAutoRenew := false
522-
if firstResp.AutoRenewStatus == domain.DomainFeatureStatusEnabled {
523-
computedAutoRenew = true
524-
}
521+
computedAutoRenew := firstResp.AutoRenewStatus == domain.DomainFeatureStatusEnabled
525522

526-
computedDnssec := false
527-
if firstResp.Dnssec.Status == domain.DomainFeatureStatusEnabled {
528-
computedDnssec = true
529-
}
523+
computedDnssec := firstResp.Dnssec.Status == domain.DomainFeatureStatusEnabled
530524

531525
var computedDSRecord []interface{}
532526
if firstResp.Dnssec != nil {

internal/services/function/helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ func functionUpload(ctx context.Context, m interface{}, functionAPI *function.AP
6666
return fmt.Errorf("failed to fetch upload url: %w", err)
6767
}
6868

69-
zip, err := os.Open(zipFile)
69+
zip, err := os.Open(zipFile) //nolint:gosec
7070
if err != nil {
7171
return fmt.Errorf("failed to read zip file: %w", err)
7272
}
73-
defer zip.Close()
73+
defer zip.Close() //nolint: errcheck
7474

7575
req, err := http.NewRequest(http.MethodPut, uploadURL.URL, zip)
7676
if err != nil {
@@ -92,7 +92,7 @@ func functionUpload(ctx context.Context, m interface{}, functionAPI *function.AP
9292
if err != nil {
9393
return fmt.Errorf("failed to send request: %w", err)
9494
}
95-
defer resp.Body.Close()
95+
defer resp.Body.Close() //nolint: errcheck
9696

9797
respDump, err := httputil.DumpResponse(resp, true)
9898
if err != nil {

internal/services/instance/instancehelpers/block.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ type UnknownSnapshot struct {
125125
}
126126

127127
func (api *BlockAndInstanceAPI) GetUnknownVolume(req *GetUnknownVolumeRequest, opts ...scw.RequestOption) (*UnknownVolume, error) {
128-
getVolumeResponse, err := api.API.GetVolume(&instance.GetVolumeRequest{
128+
getVolumeResponse, err := api.GetVolume(&instance.GetVolumeRequest{
129129
Zone: req.Zone,
130130
VolumeID: req.VolumeID,
131131
}, opts...)
@@ -194,7 +194,7 @@ func (api *BlockAndInstanceAPI) ResizeUnknownVolume(req *ResizeUnknownVolumeRequ
194194
Size: req.Size,
195195
}, opts...)
196196
} else {
197-
_, err = api.API.UpdateVolume(&instance.UpdateVolumeRequest{
197+
_, err = api.UpdateVolume(&instance.UpdateVolumeRequest{
198198
Zone: req.Zone,
199199
VolumeID: req.VolumeID,
200200
Size: req.Size,
@@ -219,7 +219,7 @@ func (api *BlockAndInstanceAPI) DeleteUnknownVolume(req *DeleteUnknownVolumeRequ
219219
VolumeID: req.VolumeID,
220220
}, opts...)
221221
} else {
222-
err = api.API.DeleteVolume(&instance.DeleteVolumeRequest{
222+
err = api.DeleteVolume(&instance.DeleteVolumeRequest{
223223
Zone: req.Zone,
224224
VolumeID: req.VolumeID,
225225
}, opts...)

internal/services/instance/testfuncs/sweep.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,16 @@ func testSweepServer(_ string) error {
112112
}
113113

114114
for _, srv := range listServers.Servers {
115-
if srv.State == instanceSDK.ServerStateStopped || srv.State == instanceSDK.ServerStateStoppedInPlace {
115+
switch srv.State {
116+
case instanceSDK.ServerStateStopped, instanceSDK.ServerStateStoppedInPlace:
116117
err := instanceAPI.DeleteServer(&instanceSDK.DeleteServerRequest{
117118
Zone: zone,
118119
ServerID: srv.ID,
119120
})
120121
if err != nil {
121122
return fmt.Errorf("error deleting server in sweeper: %w", err)
122123
}
123-
} else if srv.State == instanceSDK.ServerStateRunning {
124+
case instanceSDK.ServerStateRunning:
124125
_, err := instanceAPI.ServerAction(&instanceSDK.ServerActionRequest{
125126
Zone: zone,
126127
ServerID: srv.ID,

internal/services/iot/helpers_iot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func computeIotHubMQTTCa(ctx context.Context, mqttCaURL string, m interface{}) (
8787
return "", err
8888
}
8989

90-
defer mqttCa.Body.Close()
90+
defer mqttCa.Body.Close() //nolint: errcheck
9191
resp, _ := io.ReadAll(mqttCa.Body)
9292

9393
return string(resp), nil

internal/services/k8s/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func ResourceK8SClusterCreate(ctx context.Context, d *schema.ResourceData, m int
446446
// check if either all or none of the auto upgrade attribute are set.
447447
// if one auto upgrade attribute is set, they all must be set.
448448
// if none is set, auto upgrade attributes will be computed.
449-
if !(okAutoUpgradeDay && okAutoUpgradeStartHour) {
449+
if !okAutoUpgradeDay || !okAutoUpgradeStartHour {
450450
return append(diag.FromErr(errors.New("all field or zero field of auto_upgrade must be set")), diags...)
451451
}
452452
}

internal/services/registry/testfuncs/checks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func PushImageToRegistry(tt *acctest.TestTools, registryEndpoint string, tagName
5656
if err != nil {
5757
return fmt.Errorf("could not pull image: %w", err)
5858
}
59-
defer out.Close()
59+
defer out.Close() //nolint: errcheck
6060

6161
buffIOReader := bufio.NewReader(out)
6262

@@ -87,7 +87,7 @@ func PushImageToRegistry(tt *acctest.TestTools, registryEndpoint string, tagName
8787
if err != nil {
8888
return fmt.Errorf("could not push image: %w", err)
8989
}
90-
defer pusher.Close()
90+
defer pusher.Close() //nolint: errcheck
9191

9292
buffIOReader = bufio.NewReader(pusher)
9393

internal/services/vpc/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func flattenAndSortIPNetSubnets(subnets []scw.IPNet) (interface{}, interface{})
8383
flatIpv6Subnets = append(flatIpv6Subnets, map[string]interface{}{
8484
"subnet": sub,
8585
"address": s.IP.String(),
86-
"subnet_mask": maskHexToDottedDecimal(s.IPNet.Mask),
86+
"subnet_mask": maskHexToDottedDecimal(s.Mask),
8787
"prefix_length": getPrefixLength(s.Mask),
8888
})
8989
}

internal/transport/retry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ func (c *RetryableTransport) RoundTrip(r *http.Request) (*http.Response, error)
108108
return io.NopCloser(bytes.NewReader(b)), err
109109
}
110110

111-
return c.Client.Do(req)
111+
return c.Do(req)
112112
}
113113

114-
func RetryOnTransientStateError[T any, U any](action func() (T, error), waiter func() (U, error)) (T, error) { //nolint:ireturn
114+
func RetryOnTransientStateError[T any, U any](action func() (T, error), waiter func() (U, error)) (T, error) { //nolint
115115
t, err := action()
116116

117117
var transientStateError *scw.TransientStateError

0 commit comments

Comments
 (0)