Skip to content

Commit

Permalink
chore: enable unnecessary-stmt from revive (#21398)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 authored Jan 7, 2025
1 parent f39b425 commit 50c49ec
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ linters-settings:
# warns when an exported function or method returns a value of an un-exported type.
- name: unexported-return
disabled: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unnecessary-stmt
- name: unnecessary-stmt
disabled: false
# spots and proposes to remove unreachable code. also helps to spot errors
- name: unreachable-code
disabled: false
Expand Down
21 changes: 7 additions & 14 deletions applicationset/services/scm_provider/bitbucket_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ func TestGetBranchesBranchPagination(t *testing.T) {
func TestGetBranchesDefaultOnly(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Empty(t, r.Header.Get("Authorization"))
switch r.RequestURI {
case "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default":
if r.RequestURI == "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default" {
_, err := io.WriteString(w, `{
"id": "refs/heads/default",
"displayId": "default",
Expand Down Expand Up @@ -350,8 +349,7 @@ func TestGetBranchesDefaultOnly(t *testing.T) {
func TestGetBranchesMissingDefault(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Empty(t, r.Header.Get("Authorization"))
switch r.RequestURI {
case "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default":
if r.RequestURI == "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default" {
http.Error(w, "Not found", http.StatusNotFound)
}
defaultHandler(t)(w, r)
Expand All @@ -373,8 +371,7 @@ func TestGetBranchesMissingDefault(t *testing.T) {
func TestGetBranchesEmptyRepo(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Empty(t, r.Header.Get("Authorization"))
switch r.RequestURI {
case "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default":
if r.RequestURI == "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default" {
return
}
}))
Expand All @@ -395,8 +392,7 @@ func TestGetBranchesEmptyRepo(t *testing.T) {
func TestGetBranchesErrorDefaultBranch(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Empty(t, r.Header.Get("Authorization"))
switch r.RequestURI {
case "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default":
if r.RequestURI == "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default" {
http.Error(w, "Internal server error", http.StatusInternalServerError)
}
defaultHandler(t)(w, r)
Expand Down Expand Up @@ -510,8 +506,7 @@ func TestListReposBearerAuth(t *testing.T) {
func TestListReposDefaultBranch(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Empty(t, r.Header.Get("Authorization"))
switch r.RequestURI {
case "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default":
if r.RequestURI == "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default" {
_, err := io.WriteString(w, `{
"id": "refs/heads/default",
"displayId": "default",
Expand Down Expand Up @@ -547,8 +542,7 @@ func TestListReposDefaultBranch(t *testing.T) {
func TestListReposMissingDefaultBranch(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Empty(t, r.Header.Get("Authorization"))
switch r.RequestURI {
case "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default":
if r.RequestURI == "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default" {
http.Error(w, "Not found", http.StatusNotFound)
}
defaultHandler(t)(w, r)
Expand All @@ -564,8 +558,7 @@ func TestListReposMissingDefaultBranch(t *testing.T) {
func TestListReposErrorDefaultBranch(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Empty(t, r.Header.Get("Authorization"))
switch r.RequestURI {
case "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default":
if r.RequestURI == "/rest/api/1.0/projects/PROJECT/repos/REPO/branches/default" {
http.Error(w, "Internal server error", http.StatusInternalServerError)
}
defaultHandler(t)(w, r)
Expand Down
3 changes: 1 addition & 2 deletions cmd/argocd/commands/admin/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ func checkAppHasNoNeedToStopOperation(liveObj unstructured.Unstructured, stopOpe
if !stopOperation {
return true
}
switch liveObj.GetKind() {
case application.ApplicationKind:
if liveObj.GetKind() == application.ApplicationKind {
return liveObj.Object["operation"] == nil
}
return true
Expand Down
3 changes: 1 addition & 2 deletions controller/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,7 @@ func isResourceQuotaConflictErr(err error) bool {

func isTransientNetworkErr(err error) bool {
var netErr net.Error
switch {
case errors.As(err, &netErr):
if errors.As(err, &netErr) {
var dnsErr *net.DNSError
var opErr *net.OpError
var unknownNetworkErr net.UnknownNetworkError
Expand Down
3 changes: 1 addition & 2 deletions controller/cache/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func populateNodeInfo(un *unstructured.Unstructured, res *ResourceInfo, customLa
populateHostNodeInfo(un, res)
}
case "extensions", "networking.k8s.io":
switch gvk.Kind {
case kube.IngressKind:
if gvk.Kind == kube.IngressKind {
populateIngressInfo(un, res)
}
case "networking.istio.io":
Expand Down
6 changes: 2 additions & 4 deletions hack/gen-resources/generators/application_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func (generator *ApplicationGenerator) buildRandomSource(repositories []*v1alpha
}

func (generator *ApplicationGenerator) buildSource(opts *util.GenerateOpts, repositories []*v1alpha1.Repository) (*v1alpha1.ApplicationSource, error) {
switch opts.ApplicationOpts.SourceOpts.Strategy {
case "Random":
if opts.ApplicationOpts.SourceOpts.Strategy == "Random" {
return generator.buildRandomSource(repositories)
}
return generator.buildRandomSource(repositories)
Expand All @@ -57,8 +56,7 @@ func (generator *ApplicationGenerator) buildRandomDestination(opts *util.Generat
}

func (generator *ApplicationGenerator) buildDestination(opts *util.GenerateOpts, clusters []v1alpha1.Cluster) (*v1alpha1.ApplicationDestination, error) {
switch opts.ApplicationOpts.DestinationOpts.Strategy {
case "Random":
if opts.ApplicationOpts.DestinationOpts.Strategy == "Random" {
return generator.buildRandomDestination(opts, clusters)
}
return generator.buildRandomDestination(opts, clusters)
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,8 @@ func (spec *ApplicationSpec) GetSourcePtrByIndex(sourceIndex int) *ApplicationSo

// AllowsConcurrentProcessing returns true if given application source can be processed concurrently
func (source *ApplicationSource) AllowsConcurrentProcessing() bool {
switch {
// Kustomize with parameters requires changing kustomization.yaml file
case source.Kustomize != nil:
if source.Kustomize != nil {
return source.Kustomize.AllowsConcurrentProcessing()
}
return true
Expand Down
3 changes: 1 addition & 2 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2477,8 +2477,7 @@ func (s *Server) RunResourceAction(ctx context.Context, q *application.ResourceA
if err != nil {
return nil, err
}
switch impactedResource.K8SOperation {
case lua.CreateOperation:
if impactedResource.K8SOperation == lua.CreateOperation {
createOptions := metav1.CreateOptions{DryRun: []string{"All"}}
_, err := s.kubectl.CreateResource(ctx, config, newObj.GroupVersionKind(), newObj.GetName(), newObj.GetNamespace(), newObj, createOptions)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions util/grpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func gitErrToGRPC(err error) error {
errMsg = grpcStatus.Message()
}

switch errMsg {
case giterr.ErrRepositoryNotFound.Error():
if errMsg == giterr.ErrRepositoryNotFound.Error() {
err = rewrapError(errors.New(errMsg), codes.NotFound)
}
return err
Expand Down
3 changes: 1 addition & 2 deletions util/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ func SetAppInstanceLabel(target *unstructured.Unstructured, key, val string) err
}
}
case "batch":
switch gvk.Kind {
case kube.JobKind:
if gvk.Kind == kube.JobKind {
templateLabels, ok, err := unstructured.NestedMap(target.UnstructuredContent(), "spec", "template", "metadata", "labels")
if err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions util/kustomize/kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ func TestKustomizeBuild(t *testing.T) {
}

for _, image := range images {
switch image {
case "nginx":
if image == "nginx" {
assert.Equal(t, "1.15.5", image)
}
}
Expand Down
3 changes: 1 addition & 2 deletions util/lua/custom_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func (t testNormalizer) Normalize(un *unstructured.Unstructured) error {
if un == nil {
return nil
}
switch un.GetKind() {
case "Job":
if un.GetKind() == "Job" {
err := unstructured.SetNestedField(un.Object, map[string]any{"name": "not sure why this works"}, "metadata")
if err != nil {
return fmt.Errorf("failed to normalize Job: %w", err)
Expand Down
3 changes: 1 addition & 2 deletions util/lua/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ func isActionDisabled(actionsMap any) bool {
return false
}
for key, val := range actions {
switch vv := val.(type) {
case bool:
if vv, ok := val.(bool); ok {
if key == "disabled" {
return vv
}
Expand Down
18 changes: 8 additions & 10 deletions util/rbac/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,15 @@ func (e *Enforcer) EnforceErr(rvals ...any) error {
for i, rval := range rvals[1:] {
rvalsStrs[i] = fmt.Sprintf("%s", rval)
}
switch s := rvals[0].(type) {
case jwt.Claims:
if s, ok := rvals[0].(jwt.Claims); ok {
claims, err := jwtutil.MapClaims(s)
if err != nil {
break
}
if sub := jwtutil.StringField(claims, "sub"); sub != "" {
rvalsStrs = append(rvalsStrs, "sub: "+sub)
}
if issuedAtTime, err := jwtutil.IssuedAtTime(claims); err == nil {
rvalsStrs = append(rvalsStrs, "iat: "+issuedAtTime.Format(time.RFC3339))
if err == nil {
if sub := jwtutil.StringField(claims, "sub"); sub != "" {
rvalsStrs = append(rvalsStrs, "sub: "+sub)
}
if issuedAtTime, err := jwtutil.IssuedAtTime(claims); err == nil {
rvalsStrs = append(rvalsStrs, "iat: "+issuedAtTime.Format(time.RFC3339))
}
}
}
errMsg = fmt.Sprintf("%s: %s", errMsg, strings.Join(rvalsStrs, ", "))
Expand Down

0 comments on commit 50c49ec

Please sign in to comment.