mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
chore(lint): enable emptyStringTest rule from go-critic (#23400)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -57,7 +57,6 @@ linters:
|
||||
- builtinShadow
|
||||
- commentedOutCode
|
||||
- deferInLoop
|
||||
- emptyStringTest
|
||||
- exitAfterDefer
|
||||
- exposedSyncMutex
|
||||
- evalOrder
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -98,7 +98,7 @@ func (h *DefaultPluginHandler) lookForPlugin(filename string) (string, bool) {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(path) == 0 {
|
||||
if path == "" {
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
4
controller/cache/info.go
vendored
4
controller/cache/info.go
vendored
@@ -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:
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user