Skip to content

Commit

Permalink
chore: enable unused and ginkgo linters (#1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
parametalol authored Jan 30, 2024
1 parent 6bc66b7 commit a092092
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 24 deletions.
7 changes: 3 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ linters-settings:
includes:
- G601
revive:
min-confidence: 0
rules:
- name: blank-imports
- name: context-as-argument
Expand Down Expand Up @@ -87,14 +86,13 @@ linters-settings:
enabled-checks:
- commentFormatting
nolintlint:
allow-leading-space: false # require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
staticcheck:
go: "1.20"
checks: [ all,-ST1000,-ST1001,-ST1003,-ST1005,-SA1019,-SA4001,-ST1016 ]
wrapcheck:
wrapcheck: {}
# ignoreSigRegexps: uncomment to add ignore rules

linters:
Expand All @@ -114,6 +112,7 @@ linters:
# - gochecknoinits
# - gocognit
# - goconst
- ginkgolinter
- exportloopref
- gocritic
# - gocyclo
Expand Down Expand Up @@ -146,7 +145,7 @@ linters:
# - typecheck
# - unconvert
# - unparam
# - unused
- unused
# - varcheck
# - whitespace
- wrapcheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/config"
"github.com/stackrox/acs-fleet-manager/pkg/api"

apiErrors "github.com/stackrox/acs-fleet-manager/pkg/errors"
"github.com/stretchr/testify/require"

serviceErrors "github.com/stackrox/acs-fleet-manager/pkg/errors"
Expand Down Expand Up @@ -77,12 +76,12 @@ func TestFirstClusterPlacementStrategy(t *testing.T) {
newClusterServiceMock: func() ClusterService {
return &ClusterServiceMock{
FindAllClustersFunc: func(criteria FindClusterCriteria) ([]*api.Cluster, *serviceErrors.ServiceError) {
return nil, serviceErrors.New(apiErrors.ErrorGeneral, "error in FindAllClusters")
return nil, serviceErrors.New(serviceErrors.ErrorGeneral, "error in FindAllClusters")
},
}
},
central: centralRequest,
expectedError: serviceErrors.New(apiErrors.ErrorGeneral, "error in FindAllClusters"),
expectedError: serviceErrors.New(serviceErrors.ErrorGeneral, "error in FindAllClusters"),
expectedCluster: nil,
},
{
Expand Down
8 changes: 0 additions & 8 deletions internal/dinosaur/pkg/services/data_plane_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ type DataPlaneClusterService interface {

var _ DataPlaneClusterService = &dataPlaneClusterService{}

const dataPlaneClusterStatusCondReadyName = "Ready"

type dataPlaneClusterService struct {
di.Inject
ClusterService ClusterService
Expand Down Expand Up @@ -88,9 +86,3 @@ func (d *dataPlaneClusterService) setClusterStatus(cluster *api.Cluster, status
}
return nil
}

func (d *dataPlaneClusterService) clusterCanProcessStatusReports(cluster *api.Cluster) bool {
return cluster.Status == api.ClusterReady ||
cluster.Status == api.ClusterComputeNodeScalingUp ||
cluster.Status == api.ClusterFull
}
2 changes: 1 addition & 1 deletion internal/dinosaur/pkg/services/dinosaur.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (k *dinosaurService) DetectInstanceType(dinosaurRequest *dbapi.CentralReque
// reserveQuota - reserves quota for the given dinosaur request. If a RHACS quota has been assigned, it will try to reserve RHACS quota, otherwise it will try with RHACSTrial
func (k *dinosaurService) reserveQuota(ctx context.Context, dinosaurRequest *dbapi.CentralRequest) (subscriptionID string, err *errors.ServiceError) {
if dinosaurRequest.InstanceType == types.EVAL.String() &&
(environments.GetEnvironmentStrFromEnv() == environments.DevelopmentEnv || environments.GetEnvironmentStrFromEnv() == environments.TestingEnv) == false {
!(environments.GetEnvironmentStrFromEnv() == environments.DevelopmentEnv || environments.GetEnvironmentStrFromEnv() == environments.TestingEnv) {
if !k.dinosaurConfig.Quota.AllowEvaluatorInstance {
return "", errors.NewWithCause(errors.ErrorForbidden, err, "central eval instances are not allowed")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dinosaur/pkg/services/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func replaceHostSpecialChar(name string) (string, error) {
// This should never fail based on above replacement of invalid characters.
validationErrors := validation.IsDNS1035Label(replacedName)
if len(validationErrors) > 0 {
return replacedName, fmt.Errorf("Host name is not valid: %s. A DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character, regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?'", strings.Join(validationErrors[:], ","))
return replacedName, fmt.Errorf("host name %q is not valid: a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character, regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?'", strings.Join(validationErrors[:], ","))
}

return replacedName, nil
Expand Down
13 changes: 6 additions & 7 deletions internal/dinosaur/pkg/services/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stackrox/acs-fleet-manager/pkg/shared"

pkgErr "github.com/pkg/errors"
"github.com/stackrox/acs-fleet-manager/pkg/errors"
serviceError "github.com/stackrox/acs-fleet-manager/pkg/errors"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -83,23 +82,23 @@ func Test_handleCreateError(t *testing.T) {
tests := []struct {
name string
args args
want *errors.ServiceError
want *serviceError.ServiceError
}{
{
name: "Handler should return a general error for any other errors than violating unique constraints",
args: args{
resourceType: resourceType,
err: gorm.ErrInvalidField,
},
want: errors.GeneralError("Unable to create %s: %s", resourceType, gorm.ErrInvalidField.Error()),
want: serviceError.GeneralError("Unable to create %s: %s", resourceType, gorm.ErrInvalidField.Error()),
},
{
name: "Handler should return a conflict error if creation error is due to violating unique constraints",
args: args{
resourceType: resourceType,
err: fmt.Errorf("transaction violates unique constraints"),
},
want: errors.Conflict("This %s already exists", resourceType),
want: serviceError.Conflict("This %s already exists", resourceType),
},
}
for _, tt := range tests {
Expand All @@ -119,23 +118,23 @@ func Test_handleUpdateError(t *testing.T) {
tests := []struct {
name string
args args
want *errors.ServiceError
want *serviceError.ServiceError
}{
{
name: "Handler should return a general error for any other errors than violating unique constraints",
args: args{
resourceType: resourceType,
err: gorm.ErrInvalidData,
},
want: errors.GeneralError("Unable to update %s: %s", resourceType, gorm.ErrInvalidData.Error()),
want: serviceError.GeneralError("Unable to update %s: %s", resourceType, gorm.ErrInvalidData.Error()),
},
{
name: "Handler should return a conflict error if update error is due to violating unique constraints",
args: args{
resourceType: resourceType,
err: fmt.Errorf("transaction violates unique constraints"),
},
want: errors.Conflict("Changes to %s conflict with existing records", resourceType),
want: serviceError.Conflict("Changes to %s conflict with existing records", resourceType),
},
}
for _, tt := range tests {
Expand Down

0 comments on commit a092092

Please sign in to comment.