Skip to content

chore: migrate to golangci-lint v2 #2488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
37 changes: 21 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
# Golang CI pipeline configuration
#
# To execute linters in local the ./scripts/lint.sh script can be used.
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:
disable-all: true

# Run golangci-lint linters to see
default: none
enable:
- asasalint # check for pass []any as any in variadic func(...any) [fast: false, auto-fix: false]
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false]
Expand All @@ -21,20 +26,15 @@ linters:
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
- 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. [fast: false, auto-fix: false]
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, 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]
- gosimple #(megacheck): Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]
- grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false]
- importas # Enforces consistent import aliases [fast: false, auto-fix: false]
- ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
Expand All @@ -59,24 +59,29 @@ 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]
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false]
- testifylint # Checks usage of github.com/stretchr/testify. [fast: false, 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]
- wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false]
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]
- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` [fast: false, auto-fix: false]

settings:
revive:
rules:
- name: exported
disabled: true

exclusions:
rules:
- path: _test\.go
linters:
- stylecheck
- gosec

issues:
max-issues-per-linter: 0
max-same-issues: 0

exclude-rules:
- path: _test\.go
linters:
- stylecheck
- gosec
6 changes: 3 additions & 3 deletions api/instance/v1/instance_sdk_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestServerUpdate(t *testing.T) {
serverID = createServerResponse.Server.ID

testhelpers.Assert(t, createServerResponse.Server != nil, "Should have server in response")
testhelpers.Assert(t, 1 == len(createServerResponse.Server.Volumes), "should have exactly one volume because we didn't pass volumes map in the requests.")
testhelpers.Assert(t, len(createServerResponse.Server.Volumes) == 1, "should have exactly one volume because we didn't pass volumes map in the requests.")
for _, volume := range createServerResponse.Server.Volumes {
volumeID = volume.ID
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestServerUpdate(t *testing.T) {
testhelpers.Equals(t, bootType, updateServerResponse.Server.BootType)
testhelpers.Equals(t, commercialType, updateServerResponse.Server.CommercialType)
testhelpers.Equals(t, *dynamicIPRequired, updateServerResponse.Server.DynamicIPRequired)
testhelpers.Assert(t, 1 == len(updateServerResponse.Server.Volumes), "should have exactly one volume because we didn't pass volumes map in the requests.")
testhelpers.Assert(t, len(updateServerResponse.Server.Volumes) == 1, "should have exactly one volume because we didn't pass volumes map in the requests.")

testhelpers.Equals(t, newName, updateServerResponse.Server.Name)
testhelpers.Equals(t, updatedTags, updateServerResponse.Server.Tags)
Expand All @@ -124,7 +124,7 @@ func TestServerUpdate(t *testing.T) {
})
testhelpers.AssertNoError(t, err)
testhelpers.Assert(t, updateServerResponse.Server != nil, "Should have server in response")
testhelpers.Assert(t, 0 == len(updateServerResponse.Server.Volumes), "volume should be detached from server.")
testhelpers.Assert(t, len(updateServerResponse.Server.Volumes) == 0, "volume should be detached from server.")
})

t.Run("cleanup server and volume", func(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions api/instance/v1/sweepers/sweepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ func SweepServers(scwClient *scw.Client, zone scw.Zone) error {
}

for _, srv := range listServers.Servers {
if srv.State == instance.ServerStateStopped || srv.State == instance.ServerStateStoppedInPlace {
switch srv.State {
case instance.ServerStateStopped, instance.ServerStateStoppedInPlace:
err := instanceAPI.DeleteServer(&instance.DeleteServerRequest{
Zone: zone,
ServerID: srv.ID,
})
if err != nil {
return fmt.Errorf("error deleting server in sweeper: %s", err)
}
} else if srv.State == instance.ServerStateRunning {
case instance.ServerStateRunning:
_, err := instanceAPI.ServerAction(&instance.ServerActionRequest{
Zone: zone,
ServerID: srv.ID,
Expand Down
Loading