diff --git a/.golangci.yaml b/.golangci.yaml index 65252c81b2..e1c00241cf 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -57,7 +57,6 @@ linters: - builtinShadow - commentedOutCode - deferInLoop - - emptyStringTest - exitAfterDefer - exposedSyncMutex - evalOrder diff --git a/applicationset/generators/git.go b/applicationset/generators/git.go index 4afadec31b..891fababef 100644 --- a/applicationset/generators/git.go +++ b/applicationset/generators/git.go @@ -278,7 +278,7 @@ func (g *GitGenerator) generateParamsFromGitFile(filePath string, fileContent [] params[pathParamName+".basenameNormalized"] = utils.SanitizeName(path.Base(params[pathParamName].(string))) params[pathParamName+".filenameNormalized"] = utils.SanitizeName(path.Base(params[pathParamName+".filename"].(string))) for k, v := range strings.Split(params[pathParamName].(string), "/") { - if len(v) > 0 { + if v != "" { params[pathParamName+"["+strconv.Itoa(k)+"]"] = v } } @@ -353,7 +353,7 @@ func (g *GitGenerator) generateParamsFromApps(requestedApps []string, appSetGene params[pathParamName+".basename"] = path.Base(a) params[pathParamName+".basenameNormalized"] = utils.SanitizeName(path.Base(a)) for k, v := range strings.Split(params[pathParamName].(string), "/") { - if len(v) > 0 { + if v != "" { params[pathParamName+"["+strconv.Itoa(k)+"]"] = v } } diff --git a/applicationset/generators/list.go b/applicationset/generators/list.go index 36b67a7bfa..692184915b 100644 --- a/applicationset/generators/list.go +++ b/applicationset/generators/list.go @@ -77,7 +77,7 @@ func (g *ListGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.Appli } // Append elements from ElementsYaml to the response - if len(appSetGenerator.List.ElementsYaml) > 0 { + if appSetGenerator.List.ElementsYaml != "" { var yamlElements []map[string]any err := yaml.Unmarshal([]byte(appSetGenerator.List.ElementsYaml), &yamlElements) if err != nil { diff --git a/applicationset/services/internal/http/client.go b/applicationset/services/internal/http/client.go index b16bd873e6..c489310834 100644 --- a/applicationset/services/internal/http/client.go +++ b/applicationset/services/internal/http/client.go @@ -91,7 +91,7 @@ func (c *Client) NewRequestWithContext(ctx context.Context, method, path string, req.Header.Set("Content-Type", "application/json") } - if len(c.token) != 0 { + if c.token != "" { req.Header.Set("Authorization", "Bearer "+c.token) } diff --git a/applicationset/utils/utils.go b/applicationset/utils/utils.go index 368fcbb6c9..dcde03c0be 100644 --- a/applicationset/utils/utils.go +++ b/applicationset/utils/utils.go @@ -65,7 +65,7 @@ func copyUnexported(copy, original reflect.Value) { func IsJSONStr(str string) bool { str = strings.TrimSpace(str) - return len(str) > 0 && str[0] == '{' + return str != "" && str[0] == '{' } func ConvertYAMLToJSON(str string) (string, error) { @@ -335,7 +335,7 @@ func (r *Render) Replace(tmpl string, replaceMap map[string]any, useGoTemplate b replacedTmpl := fstTmpl.ExecuteFuncString(func(w io.Writer, tag string) (int, error) { trimmedTag := strings.TrimSpace(tag) replacement, ok := replaceMap[trimmedTag].(string) - if len(trimmedTag) == 0 || !ok { + if trimmedTag == "" || !ok { return fmt.Fprintf(w, "{{%s}}", tag) } return w.Write([]byte(replacement)) diff --git a/cmd/argocd/commands/cluster.go b/cmd/argocd/commands/cluster.go index 6d6822a963..a6860cbb75 100644 --- a/cmd/argocd/commands/cluster.go +++ b/cmd/argocd/commands/cluster.go @@ -171,7 +171,7 @@ func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clie clst.Server = argoappv1.KubernetesInternalAPIServerAddr } else if clusterOpts.ClusterEndpoint == string(cmdutil.KubePublicEndpoint) { endpoint, caData, err := cmdutil.GetKubePublicEndpoint(clientset) - if err != nil || len(endpoint) == 0 { + if err != nil || endpoint == "" { log.Warnf("Failed to find the cluster endpoint from kube-public data: %v", err) log.Infof("Falling back to the endpoint '%s' as listed in the kubeconfig context", clst.Server) endpoint = clst.Server diff --git a/cmd/argocd/commands/plugin.go b/cmd/argocd/commands/plugin.go index 47e5a40e1a..3ebdf27c2f 100644 --- a/cmd/argocd/commands/plugin.go +++ b/cmd/argocd/commands/plugin.go @@ -98,7 +98,7 @@ func (h *DefaultPluginHandler) lookForPlugin(filename string) (string, bool) { continue } - if len(path) == 0 { + if path == "" { return "", false } diff --git a/cmd/util/app.go b/cmd/util/app.go index 7f3ba56615..8ee222149c 100644 --- a/cmd/util/app.go +++ b/cmd/util/app.go @@ -429,7 +429,7 @@ func setHelmOpt(src *argoappv1.ApplicationSource, opts helmOpts) { if opts.ignoreMissingValueFiles { src.Helm.IgnoreMissingValueFiles = opts.ignoreMissingValueFiles } - if len(opts.values) > 0 { + if opts.values != "" { err := src.Helm.SetValuesString(opts.values) if err != nil { log.Fatal(err) diff --git a/cmd/util/cluster_test.go b/cmd/util/cluster_test.go index 3706b2d7df..400b2802b3 100644 --- a/cmd/util/cluster_test.go +++ b/cmd/util/cluster_test.go @@ -193,7 +193,7 @@ func TestGetKubePublicEndpoint(t *testing.T) { func kubeconfigFixture(endpoint string, certificateAuthorityData []byte) string { kubeconfig := &clientcmdapiv1.Config{} - if len(endpoint) > 0 { + if endpoint != "" { kubeconfig.Clusters = []clientcmdapiv1.NamedCluster{ { Name: "test-kube", diff --git a/cmpserver/plugin/plugin.go b/cmpserver/plugin/plugin.go index d52a9ca3a7..f8b63b4f5b 100644 --- a/cmpserver/plugin/plugin.go +++ b/cmpserver/plugin/plugin.go @@ -136,7 +136,7 @@ func runCommand(ctx context.Context, command Command, path string, env []string) "stderr": stderr.String(), "command": command, }) - if len(output) == 0 { + if output == "" { logCtx.Warn("Plugin command returned zero output") } else { // Log stderr even on successful commands to help develop plugins diff --git a/controller/cache/info.go b/controller/cache/info.go index db5e27a287..1eb1e46b6f 100644 --- a/controller/cache/info.go +++ b/controller/cache/info.go @@ -380,7 +380,7 @@ func populatePodInfo(un *unstructured.Unstructured, res *ResourceInfo) { continue case container.State.Terminated != nil: // initialization is failed - if len(container.State.Terminated.Reason) == 0 { + if container.State.Terminated.Reason == "" { if container.State.Terminated.Signal != 0 { reason = fmt.Sprintf("Init:Signal:%d", container.State.Terminated.Signal) } else { @@ -390,7 +390,7 @@ func populatePodInfo(un *unstructured.Unstructured, res *ResourceInfo) { reason = "Init:" + container.State.Terminated.Reason } initializing = true - case container.State.Waiting != nil && len(container.State.Waiting.Reason) > 0 && container.State.Waiting.Reason != "PodInitializing": + case container.State.Waiting != nil && container.State.Waiting.Reason != "" && container.State.Waiting.Reason != "PodInitializing": reason = "Init:" + container.State.Waiting.Reason initializing = true default: diff --git a/pkg/apis/application/v1alpha1/types.go b/pkg/apis/application/v1alpha1/types.go index 013bddfdac..5f1f4ee6a2 100644 --- a/pkg/apis/application/v1alpha1/types.go +++ b/pkg/apis/application/v1alpha1/types.go @@ -2821,7 +2821,7 @@ func (w *SyncWindow) scheduleOffsetByTimeZone() time.Duration { // AddWindow adds a sync window with the given parameters to the AppProject func (spec *AppProjectSpec) AddWindow(knd string, sch string, dur string, app []string, ns []string, cl []string, ms bool, timeZone string, andOperator bool, description string) error { - if len(knd) == 0 || len(sch) == 0 || len(dur) == 0 { + if knd == "" || sch == "" || dur == "" { return errors.New("cannot create window: require kind, schedule, duration and one or more of applications, namespaces and clusters") } @@ -3064,15 +3064,15 @@ func (w SyncWindow) active(currentTime time.Time) (bool, error) { // Update updates a sync window's settings with the given parameter func (w *SyncWindow) Update(s string, d string, a []string, n []string, c []string, tz string, description string) error { - if len(s) == 0 && len(d) == 0 && len(a) == 0 && len(n) == 0 && len(c) == 0 && len(description) == 0 { + if s == "" && d == "" && len(a) == 0 && len(n) == 0 && len(c) == 0 && description == "" { return errors.New("cannot update: require one or more of schedule, duration, application, namespace, cluster or description") } - if len(s) > 0 { + if s != "" { w.Schedule = s } - if len(d) > 0 { + if d != "" { w.Duration = d } @@ -3088,7 +3088,7 @@ func (w *SyncWindow) Update(s string, d string, a []string, n []string, c []stri w.Clusters = c } - if len(description) > 0 { + if description != "" { w.Description = description } diff --git a/server/application/application.go b/server/application/application.go index 6697392305..53fcc093a4 100644 --- a/server/application/application.go +++ b/server/application/application.go @@ -1296,7 +1296,7 @@ func (s *Server) validateAndNormalizeApp(ctx context.Context, app *v1alpha1.Appl if app.Spec.HasMultipleSources() { sourceNames := make(map[string]bool) for _, source := range app.Spec.Sources { - if len(source.Name) > 0 && sourceNames[source.Name] { + if source.Name != "" && sourceNames[source.Name] { return fmt.Errorf("application %s has duplicate source name: %s", app.Name, source.Name) } sourceNames[source.Name] = true diff --git a/server/badge/badge.go b/server/badge/badge.go index a2fb1a3b75..3f33e7a6ff 100644 --- a/server/badge/badge.go +++ b/server/badge/badge.go @@ -141,7 +141,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Sample url: http://localhost:8080/api/badge?project=default if projects, ok := r.URL.Query()["project"]; ok && enabled && !notFound { for _, p := range projects { - if errs := validation.NameIsDNSLabel(strings.ToLower(p), false); len(p) > 0 && len(errs) != 0 { + if errs := validation.NameIsDNSLabel(strings.ToLower(p), false); p != "" && len(errs) != 0 { w.WriteHeader(http.StatusBadRequest) return } diff --git a/server/server.go b/server/server.go index 975d5164fc..263c26a800 100644 --- a/server/server.go +++ b/server/server.go @@ -875,7 +875,7 @@ func (server *ArgoCDServer) watchSettings() { func (server *ArgoCDServer) rbacPolicyLoader(ctx context.Context) { err := server.enf.RunPolicyLoader(ctx, func(cm *corev1.ConfigMap) error { var scopes []string - if scopesStr, ok := cm.Data[rbac.ConfigMapScopesKey]; len(scopesStr) > 0 && ok { + if scopesStr, ok := cm.Data[rbac.ConfigMapScopesKey]; scopesStr != "" && ok { scopes = make([]string, 0) err := yaml.Unmarshal([]byte(scopesStr), &scopes) if err != nil { @@ -1381,7 +1381,7 @@ func newRedirectServer(port int, rootPath string) *http.Server { target += req.URL.Path } - if len(req.URL.RawQuery) > 0 { + if req.URL.RawQuery != "" { target += "?" + req.URL.RawQuery } http.Redirect(w, req, target, http.StatusTemporaryRedirect) diff --git a/test/e2e/fixture/admin/utils/backup.go b/test/e2e/fixture/admin/utils/backup.go index f68a5ff2b2..9af8f29ce0 100644 --- a/test/e2e/fixture/admin/utils/backup.go +++ b/test/e2e/fixture/admin/utils/backup.go @@ -17,7 +17,7 @@ func GetExportedResourcesFromOutput(output string) (ExportedResources, error) { for _, doc := range docs { doc = strings.TrimSpace(doc) - if len(doc) == 0 { + if doc == "" { continue } diff --git a/util/cert/cert.go b/util/cert/cert.go index a132be6f05..8043400af2 100644 --- a/util/cert/cert.go +++ b/util/cert/cert.go @@ -230,7 +230,7 @@ func IsValidSSHKnownHostsEntry(line string) bool { trimmedEntry := strings.TrimSpace(line) // We ignore commented out lines - usually happens when copy and pasting // to the ConfigMap from a known_hosts file or from ssh-keyscan output. - if len(trimmedEntry) == 0 || trimmedEntry[0] == '#' { + if trimmedEntry == "" || trimmedEntry[0] == '#' { return false } diff --git a/util/db/secrets.go b/util/db/secrets.go index 56c075c151..d8a99200e1 100644 --- a/util/db/secrets.go +++ b/util/db/secrets.go @@ -77,7 +77,7 @@ func updateSecretInt(secret *corev1.Secret, key string, value int64) { } func updateSecretString(secret *corev1.Secret, key, value string) { - if _, present := secret.Data[key]; present || len(value) > 0 { + if _, present := secret.Data[key]; present || value != "" { secret.Data[key] = []byte(value) } } diff --git a/util/http/http.go b/util/http/http.go index 954117d7dc..ceafca09f0 100644 --- a/util/http/http.go +++ b/util/http/http.go @@ -123,7 +123,7 @@ func JoinCookies(key string, cookieList []*http.Cookie) (string, error) { } func maxCookieValueLength(key, attributes string) int { - if len(attributes) > 0 { + if attributes != "" { return maxCookieLength - (len(key) + 3) - (len(attributes) + 2) } return maxCookieLength - (len(key) + 3) diff --git a/util/kube/portforwarder.go b/util/kube/portforwarder.go index 9a0698abd4..2c96c5fb76 100644 --- a/util/kube/portforwarder.go +++ b/util/kube/portforwarder.go @@ -116,7 +116,7 @@ func PortForward(targetPort int, namespace string, overrides *clientcmd.ConfigOv return -1, err case <-readyChan: } - if len(errOut.String()) != 0 { + if errOut.String() != "" { return -1, fmt.Errorf("%s", errOut.String()) } return port, nil diff --git a/util/templates/normalizers.go b/util/templates/normalizers.go index b507f80dd1..8dcbc31bef 100644 --- a/util/templates/normalizers.go +++ b/util/templates/normalizers.go @@ -8,7 +8,7 @@ const Indentation = ` ` // Examples normalizes a command's examples to follow the conventions. func Examples(s string) string { - if len(s) == 0 { + if s == "" { return s } return normalizer{s}.trim().indent().string diff --git a/util/webhook/webhook.go b/util/webhook/webhook.go index 43ab603dd1..11de059918 100644 --- a/util/webhook/webhook.go +++ b/util/webhook/webhook.go @@ -209,7 +209,7 @@ func (a *ArgoCDWebhookHandler) affectedRevisionInfo(payloadIf any) (webURLs []st // Get DiffSet only for authenticated webhooks. // when WebhookBitbucketUUID is set in argocd-secret, then the payload must be signed and // signature is validated before payload is parsed. - if len(a.settings.WebhookBitbucketUUID) > 0 { + if a.settings.WebhookBitbucketUUID != "" { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() argoRepo, err := a.lookupRepository(ctx, webURLs[0])