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 gosimple and other linters #2182

Merged
merged 3 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
12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,30 @@ linters:
- 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]
- contextcheck # check the function whether use a non-inherited context [fast: false, 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]
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
- 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]
- mirror # reports wrong mirror patterns of bytes/strings usage [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
2 changes: 1 addition & 1 deletion api/applesilicon/v1alpha1/apple_silicon_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ func (s *API) WaitForPossibleDeletion(req *WaitForServerRequest, opts ...scw.Req
return nil, errors.Wrap(err, "waiting for server failed")
}
timeToDelete := *server.DeletableAt
time.Sleep(timeToDelete.Sub(time.Now()))
time.Sleep(time.Until(timeToDelete))
return server, nil
}
4 changes: 2 additions & 2 deletions api/instance/v1/volume_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *API) getUnknownVolume(req *getUnknownVolumeRequest, opts ...scw.Request
}

// Try instance API
if req.IsBlockVolume == nil || *req.IsBlockVolume == false {
if req.IsBlockVolume == nil || !*req.IsBlockVolume {
getVolumeResponse, err := s.GetVolume(&GetVolumeRequest{
Zone: req.Zone,
VolumeID: req.VolumeID,
Expand All @@ -93,7 +93,7 @@ func (s *API) getUnknownVolume(req *getUnknownVolumeRequest, opts ...scw.Request
}
}

if volume.Type == "" && (req.IsBlockVolume == nil || *req.IsBlockVolume == true) {
if volume.Type == "" && (req.IsBlockVolume == nil || *req.IsBlockVolume) {
getVolumeResponse, err := block.NewAPI(s.client).GetVolume(&block.GetVolumeRequest{
Zone: req.Zone,
VolumeID: req.VolumeID,
Expand Down
2 changes: 1 addition & 1 deletion scw/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ type InvalidRequestError struct {
// ToSdkError returns a standard error InvalidArgumentsError or nil Fields is nil.
func (e *InvalidRequestError) ToInvalidArgumentsError() SdkError {
// If error has no fields, it is not an InvalidArgumentsError.
if e.Fields == nil || len(e.Fields) == 0 {
if len(e.Fields) == 0 {
return nil
}

Expand Down