Skip to content
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

chore: add support for gci, gofmt, gofumpt, goimports and whitespace #2176

Merged
merged 2 commits into from
Aug 27, 2024
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
20 changes: 20 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: golangci-lint
on:
merge_group:
pull_request:
permissions:
contents: read
checks: write
pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
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
args: --timeout 5m
34 changes: 14 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,22 @@ linters:

# Run golangci-lint linters to see
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- goconst
- goimports
- golint
- misspell
- stylecheck
- unconvert
- unparam
- whitespace
- gosec
# - wsl Could be interesting but need a lot of changes
- 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]
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
- dupword # checks for duplicate words in the source code [fast: true, auto-fix: true]
- 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]
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]

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

exclude-rules:
- path: _test\.go
linters:
Expand Down
1 change: 0 additions & 1 deletion api/applesilicon/v1alpha1/apple_silicon_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func (s *API) WaitForServer(req *WaitForServerRequest, opts ...scw.RequestOption
ServerID: req.ServerID,
Zone: req.Zone,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
1 change: 0 additions & 1 deletion api/block/v1alpha1/snapshot_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest, opts ...scw.RequestOp
SnapshotID: req.SnapshotID,
Zone: req.Zone,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
1 change: 0 additions & 1 deletion api/block/v1alpha1/volume_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (s *API) WaitForVolume(req *WaitForVolumeRequest, opts ...scw.RequestOption
VolumeID: req.VolumeID,
Zone: req.Zone,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
1 change: 0 additions & 1 deletion api/cockpit/v1beta1/cockpit_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (s *API) WaitForCockpit(
Timeout: timeout,
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
})

if err != nil {
return nil, errors.Wrap(err, "waiting for Cockpit failed")
}
Expand Down
3 changes: 2 additions & 1 deletion api/dedibox/v1/dedibox_utils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package dedibox

import (
"time"

"github.com/scaleway/scaleway-sdk-go/internal/async"
"github.com/scaleway/scaleway-sdk-go/internal/errors"
"github.com/scaleway/scaleway-sdk-go/scw"
"time"
)

const (
Expand Down
3 changes: 0 additions & 3 deletions api/documentdb/v1beta1/documentdb_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (s *API) WaitForInstance(req *WaitForInstanceRequest, opts ...scw.RequestOp
InstanceID: req.InstanceID,
Region: req.Region,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -91,7 +90,6 @@ func (s *API) WaitForInstanceLog(req *WaitForInstanceLogRequest, opts ...scw.Req
res, err := s.GetInstanceLog(&GetInstanceLogRequest{
Region: req.Region,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -139,7 +137,6 @@ func (s *API) WaitForReadReplica(req *WaitForReadReplicaRequest, opts ...scw.Req
ReadReplicaID: req.ReadReplicaID,
Region: req.Region,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
5 changes: 0 additions & 5 deletions api/domain/v2beta1/domain_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func (s *API) WaitForDNSZone(
req *WaitForDNSZoneRequest,
opts ...scw.RequestOption,
) (*DNSZone, error) {

timeout := defaultTimeout
if req.Timeout != nil {
timeout = *req.Timeout
Expand Down Expand Up @@ -62,7 +61,6 @@ func (s *API) WaitForDNSZone(

// listing dns zones and take the first one
DNSZones, err := s.ListDNSZones(listReq, opts...)

if err != nil {
return nil, false, err
}
Expand All @@ -80,7 +78,6 @@ func (s *API) WaitForDNSZone(
Timeout: timeout,
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
})

if err != nil {
return nil, errors.Wrap(err, "waiting for DNS failed")
}
Expand Down Expand Up @@ -118,7 +115,6 @@ func (s *API) WaitForDNSRecordExist(
Type: req.RecordType,
DNSZone: req.DNSZone,
}, opts...)

if err != nil {
return nil, false, err
}
Expand All @@ -134,7 +130,6 @@ func (s *API) WaitForDNSRecordExist(
Timeout: timeout,
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
})

if err != nil {
return nil, errors.Wrap(err, "check for DNS Record exist failed")
}
Expand Down
3 changes: 2 additions & 1 deletion api/inference/v1beta1/inference_utils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package inference

import (
"time"

"github.com/scaleway/scaleway-sdk-go/internal/async"
"github.com/scaleway/scaleway-sdk-go/internal/errors"
"github.com/scaleway/scaleway-sdk-go/scw"
"time"
)

const (
Expand Down
1 change: 0 additions & 1 deletion api/instance/v1/image_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (s *API) WaitForImage(req *WaitForImageRequest, opts ...scw.RequestOption)
ImageID: req.ImageID,
Zone: req.Zone,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
12 changes: 6 additions & 6 deletions api/instance/v1/instance_metadata_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"github.com/scaleway/scaleway-sdk-go/internal/errors"
)

var (
metadataRetryBindPort = 200
)
var metadataRetryBindPort = 200

const metadataAPIv4 = "http://169.254.42.42"
const metadataAPIv6 = "http://[fd00:42::42]"
const (
metadataAPIv4 = "http://169.254.42.42"
metadataAPIv6 = "http://[fd00:42::42]"
)

// MetadataAPI metadata API
type MetadataAPI struct {
Expand Down Expand Up @@ -82,7 +82,7 @@ type Metadata struct {
Organization string `json:"organization,omitempty"`
Project string `json:"project,omitempty"`
CommercialType string `json:"commercial_type,omitempty"`
//PublicIP IPv4 only
// PublicIP IPv4 only
PublicIP struct {
ID string `json:"id"`
Address string `json:"address"`
Expand Down
4 changes: 1 addition & 3 deletions api/instance/v1/instance_sdk_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ func TestCreateServerWithIncorrectBody(t *testing.T) {

instanceAPI := NewAPI(client)

var (
zone = scw.ZoneFrPar1
)
zone := scw.ZoneFrPar1

// Create server
_, err = instanceAPI.CreateServer(&CreateServerRequest{
Expand Down
6 changes: 1 addition & 5 deletions api/instance/v1/instance_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import (
"time"

"github.com/scaleway/scaleway-sdk-go/internal/async"

"github.com/scaleway/scaleway-sdk-go/internal/errors"
"github.com/scaleway/scaleway-sdk-go/scw"
)

var (
resourceLock sync.Map
)
var resourceLock sync.Map

// lockResource locks a resource from a specific resourceID
func lockResource(resourceID string) *sync.Mutex {
Expand Down Expand Up @@ -315,7 +312,6 @@ func (s *API) WaitForPrivateNIC(req *WaitForPrivateNICRequest, opts ...scw.Reque
Zone: req.Zone,
PrivateNicID: req.PrivateNicID,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
2 changes: 0 additions & 2 deletions api/instance/v1/server_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (s *API) WaitForServer(req *WaitForServerRequest, opts ...scw.RequestOption
ServerID: req.ServerID,
Zone: req.Zone,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -168,7 +167,6 @@ func (s *API) GetServerType(req *GetServerTypeRequest) (*ServerType, error) {
res, err := s.ListServersTypes(&ListServersTypesRequest{
Zone: req.Zone,
}, scw.WithAllPages())

if err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion api/instance/v1/snapshot_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest, opts ...scw.RequestOp
SnapshotID: req.SnapshotID,
Zone: req.Zone,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
4 changes: 1 addition & 3 deletions api/instance/v1/snapshot_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ func TestAPI_UpdateSnapshot(t *testing.T) {

instanceAPI := NewAPI(client)

var (
volumeSize = 1 * scw.GB
)
volumeSize := 1 * scw.GB

createVolume, err := instanceAPI.CreateVolume(&CreateVolumeRequest{
Name: "volume_name",
Expand Down
1 change: 0 additions & 1 deletion api/instance/v1/volume_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (s *API) WaitForVolume(req *WaitForVolumeRequest, opts ...scw.RequestOption
VolumeID: req.VolumeID,
Zone: req.Zone,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
1 change: 0 additions & 1 deletion api/jobs/v1alpha1/custom_job_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func (s *API) WaitForJobRun(req *WaitForJobRunRequest, opts ...scw.RequestOption
JobRunID: req.JobRunID,
Region: req.Region,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
2 changes: 0 additions & 2 deletions api/k8s/v1/k8s_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (s *API) WaitForPool(req *WaitForPoolRequest, opts ...scw.RequestOption) (*
PoolID: req.PoolID,
Region: req.Region,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -143,7 +142,6 @@ func (s *API) WaitForNode(req *WaitForNodeRequest, opts ...scw.RequestOption) (*
NodeID: req.NodeID,
Region: req.Region,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
4 changes: 1 addition & 3 deletions api/lb/v1/lb_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func waitForLb(timeout *time.Duration, retryInterval *time.Duration, getLB func(
lb, err := async.WaitSync(&async.WaitSyncConfig{
Get: func() (interface{}, bool, error) {
res, err := getLB()

if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -189,7 +188,7 @@ func waitForPNLb(timeout *time.Duration, retryInterval *time.Duration, getPNs fu
if err != nil {
return nil, false, err
}
//wait at the first not terminal state
// wait at the first not terminal state
_, isTerminal := terminalStatus[pn.Status]
if !isTerminal {
return pns, isTerminal, nil
Expand Down Expand Up @@ -259,7 +258,6 @@ func waitForLBCertificate(timeout *time.Duration, retryInterval *time.Duration,
crt, err := async.WaitSync(&async.WaitSyncConfig{
Get: func() (interface{}, bool, error) {
res, err := getCertificate()

if err != nil {
return nil, false, err
}
Expand Down
2 changes: 1 addition & 1 deletion api/marketplace/v2/marketplace_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ func TestGetImageByLabel(t *testing.T) {
ImageLabel: "foo-bar-image",
})
testhelpers.Assert(t, err != nil, "Should have error")
//testhelpers.Equals(t, "scaleway-sdk-go: couldn't find a matching image for the given label (foo-bar-image)", err.Error())
// testhelpers.Equals(t, "scaleway-sdk-go: couldn't find a matching image for the given label (foo-bar-image)", err.Error())
})
}
4 changes: 0 additions & 4 deletions api/rdb/v1/rdb_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (s *API) WaitForInstance(req *WaitForInstanceRequest, opts ...scw.RequestOp
InstanceID: req.InstanceID,
Region: req.Region,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -92,7 +91,6 @@ func (s *API) WaitForDatabaseBackup(req *WaitForDatabaseBackupRequest, opts ...s
DatabaseBackupID: req.DatabaseBackupID,
Region: req.Region,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -139,7 +137,6 @@ func (s *API) WaitForInstanceLog(req *WaitForInstanceLogRequest, opts ...scw.Req
Region: req.Region,
InstanceLogID: req.InstanceLogID,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -187,7 +184,6 @@ func (s *API) WaitForReadReplica(req *WaitForReadReplicaRequest, opts ...scw.Req
ReadReplicaID: req.ReadReplicaID,
Region: req.Region,
}, opts...)

if err != nil {
return nil, false, err
}
Expand Down
Loading