Skip to content

Commit b937449

Browse files
authored
chore: enable modernize linter (argoproj#15445)
Signed-off-by: Alan Clucas <alan@clucas.org>
1 parent df349b3 commit b937449

134 files changed

Lines changed: 593 additions & 597 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ linters:
2121
- iotamixing
2222
- mirror
2323
- misspell
24+
- modernize
2425
- nakedret
2526
- nilerr
2627
- noctx

api/openapi-spec/swagger_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11-
type obj = map[string]interface{}
11+
type obj = map[string]any
1212

1313
func TestSwagger(t *testing.T) {
1414
swagger := obj{}

cmd/argo/commands/common/get.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,13 @@ func printNode(w *tabwriter.Writer, node wfv1.NodeStatus, wfName, nodePrefix str
498498
} else if node.TemplateName != "" {
499499
fmtTemplateName = node.TemplateName
500500
}
501-
var args []interface{}
501+
var args []any
502502
duration := humanize.RelativeDurationShort(node.StartedAt.Time, node.FinishedAt.Time)
503503
if node.Type == wfv1.NodeTypePod {
504504
podName := util.GeneratePodName(wfName, nodeName, templateName, node.ID, podNameVersion)
505-
args = []interface{}{nodePrefix, fmtNodeName, fmtTemplateName, podName, duration, node.Message, ""}
505+
args = []any{nodePrefix, fmtNodeName, fmtTemplateName, podName, duration, node.Message, ""}
506506
} else {
507-
args = []interface{}{nodePrefix, fmtNodeName, fmtTemplateName, "", "", node.Message, ""}
507+
args = []any{nodePrefix, fmtNodeName, fmtTemplateName, "", "", node.Message, ""}
508508
}
509509
switch getArgs.Output.String() {
510510
case "wide":

cmd/argo/commands/convert.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func convertDocument(data []byte, outputFormat string, isJSON bool) error {
9393
return fmt.Errorf("failed to parse TypeMeta: %w", err)
9494
}
9595

96-
var converted interface{}
96+
var converted any
9797

9898
// Parse into legacy type and convert to current type
9999
switch typeMeta.Kind {
@@ -128,7 +128,7 @@ func convertDocument(data []byte, outputFormat string, isJSON bool) error {
128128
default:
129129
// Unknown type - pass through unchanged
130130
// Re-parse as generic map to preserve structure
131-
var generic map[string]interface{}
131+
var generic map[string]any
132132
if err := yaml.Unmarshal(data, &generic); err != nil {
133133
return fmt.Errorf("failed to parse unknown kind %s: %w", typeMeta.Kind, err)
134134
}
@@ -138,7 +138,7 @@ func convertDocument(data []byte, outputFormat string, isJSON bool) error {
138138
return outputObject(converted, outputFormat, isJSON)
139139
}
140140

141-
func outputObject(obj interface{}, format string, preferJSON bool) error {
141+
func outputObject(obj any, format string, preferJSON bool) error {
142142
var outBytes []byte
143143
var err error
144144

cmd/argo/commands/cron/backfill.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func CreateMonitorWf(ctx context.Context, wf, namespace, cronWFName string, sche
213213
startIdx := 0
214214
var endIdx int
215215
var wfNames []string
216-
for i := 0; i < iterCount; i++ {
216+
for i := range iterCount {
217217
tmpl := monitorWfObj.GetTemplateByName("create-workflow")
218218
if (TotalScheCount - i*cliOps.maxWorkflowCount) < cliOps.maxWorkflowCount {
219219
endIdx = TotalScheCount

cmd/argo/commands/cron/util.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,48 +95,48 @@ func printCronWorkflow(ctx context.Context, wf *v1alpha1.CronWorkflow, outFmt st
9595
func getCronWorkflowGet(ctx context.Context, cwf *v1alpha1.CronWorkflow) string {
9696
const fmtStr = "%-30s %v\n"
9797

98-
out := ""
99-
out += fmt.Sprintf(fmtStr, "Name:", cwf.Name)
100-
out += fmt.Sprintf(fmtStr, "Namespace:", cwf.Namespace)
101-
out += fmt.Sprintf(fmtStr, "Created:", humanize.Timestamp(cwf.CreationTimestamp.Time))
102-
out += fmt.Sprintf(fmtStr, "Schedules:", cwf.Spec.GetScheduleString())
103-
out += fmt.Sprintf(fmtStr, "Suspended:", cwf.Spec.Suspend)
98+
var out strings.Builder
99+
out.WriteString(fmt.Sprintf(fmtStr, "Name:", cwf.Name))
100+
out.WriteString(fmt.Sprintf(fmtStr, "Namespace:", cwf.Namespace))
101+
out.WriteString(fmt.Sprintf(fmtStr, "Created:", humanize.Timestamp(cwf.CreationTimestamp.Time)))
102+
out.WriteString(fmt.Sprintf(fmtStr, "Schedules:", cwf.Spec.GetScheduleString()))
103+
out.WriteString(fmt.Sprintf(fmtStr, "Suspended:", cwf.Spec.Suspend))
104104
if cwf.Spec.Timezone != "" {
105-
out += fmt.Sprintf(fmtStr, "Timezone:", cwf.Spec.Timezone)
105+
out.WriteString(fmt.Sprintf(fmtStr, "Timezone:", cwf.Spec.Timezone))
106106
}
107107
if cwf.Spec.StartingDeadlineSeconds != nil {
108-
out += fmt.Sprintf(fmtStr, "StartingDeadlineSeconds:", *cwf.Spec.StartingDeadlineSeconds)
108+
out.WriteString(fmt.Sprintf(fmtStr, "StartingDeadlineSeconds:", *cwf.Spec.StartingDeadlineSeconds))
109109
}
110110
if cwf.Spec.ConcurrencyPolicy != "" {
111-
out += fmt.Sprintf(fmtStr, "ConcurrencyPolicy:", cwf.Spec.ConcurrencyPolicy)
111+
out.WriteString(fmt.Sprintf(fmtStr, "ConcurrencyPolicy:", cwf.Spec.ConcurrencyPolicy))
112112
}
113113
if cwf.Status.LastScheduledTime != nil {
114-
out += fmt.Sprintf(fmtStr, "LastScheduledTime:", humanize.Timestamp(cwf.Status.LastScheduledTime.Time))
114+
out.WriteString(fmt.Sprintf(fmtStr, "LastScheduledTime:", humanize.Timestamp(cwf.Status.LastScheduledTime.Time)))
115115
}
116116

117117
next, err := GetNextRuntime(ctx, cwf)
118118
if err == nil {
119-
out += fmt.Sprintf(fmtStr, "NextScheduledTime:", humanize.Timestamp(next)+" (assumes workflow-controller is in UTC)")
119+
out.WriteString(fmt.Sprintf(fmtStr, "NextScheduledTime:", humanize.Timestamp(next)+" (assumes workflow-controller is in UTC)"))
120120
}
121121

122122
if len(cwf.Status.Active) > 0 {
123123
var activeWfNames []string
124124
for _, activeWf := range cwf.Status.Active {
125125
activeWfNames = append(activeWfNames, activeWf.Name)
126126
}
127-
out += fmt.Sprintf(fmtStr, "Active Workflows:", strings.Join(activeWfNames, ", "))
127+
out.WriteString(fmt.Sprintf(fmtStr, "Active Workflows:", strings.Join(activeWfNames, ", ")))
128128
}
129129
if len(cwf.Status.Conditions) > 0 {
130-
out += cwf.Status.Conditions.DisplayString(fmtStr, map[v1alpha1.ConditionType]string{v1alpha1.ConditionTypeSubmissionError: "✖"})
130+
out.WriteString(cwf.Status.Conditions.DisplayString(fmtStr, map[v1alpha1.ConditionType]string{v1alpha1.ConditionTypeSubmissionError: "✖"}))
131131
}
132132
if len(cwf.Spec.WorkflowSpec.Arguments.Parameters) > 0 {
133-
out += fmt.Sprintf(fmtStr, "Workflow Parameters:", "")
133+
out.WriteString(fmt.Sprintf(fmtStr, "Workflow Parameters:", ""))
134134
for _, param := range cwf.Spec.WorkflowSpec.Arguments.Parameters {
135135
if !param.HasValue() {
136136
continue
137137
}
138-
out += fmt.Sprintf(fmtStr, " "+param.Name+":", param.GetValue())
138+
out.WriteString(fmt.Sprintf(fmtStr, " "+param.Name+":", param.GetValue()))
139139
}
140140
}
141-
return out
141+
return out.String()
142142
}

cmd/argoexec/commands/artifact/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func deleteArtifacts(labelSelector string, ctx context.Context, artifactGCTaskIn
114114

115115
task.Status.ArtifactResultsByNode[nodeName] = artResultNodeStatus
116116
}
117-
patch, err := json.Marshal(map[string]interface{}{"status": v1alpha1.ArtifactGCStatus{ArtifactResultsByNode: task.Status.ArtifactResultsByNode}})
117+
patch, err := json.Marshal(map[string]any{"status": v1alpha1.ArtifactGCStatus{ArtifactResultsByNode: task.Status.ArtifactResultsByNode}})
118118
if err != nil {
119119
return err
120120
}

config/ttl.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (l TTL) MarshalJSON() ([]byte, error) {
1717
}
1818

1919
func (l *TTL) UnmarshalJSON(b []byte) error {
20-
var v interface{}
20+
var v any
2121
if err := json.Unmarshal(b, &v); err != nil {
2222
return err
2323
}
@@ -27,23 +27,23 @@ func (l *TTL) UnmarshalJSON(b []byte) error {
2727
*l = 0
2828
return nil
2929
}
30-
if strings.HasSuffix(value, "d") {
31-
days, err := strconv.Atoi(strings.TrimSuffix(value, "d"))
30+
if before, ok := strings.CutSuffix(value, "d"); ok {
31+
days, err := strconv.Atoi(before)
3232
*l = TTL(time.Duration(days) * 24 * time.Hour)
3333
return err
3434
}
35-
if strings.HasSuffix(value, "h") {
36-
hours, err := strconv.Atoi(strings.TrimSuffix(value, "h"))
35+
if before, ok := strings.CutSuffix(value, "h"); ok {
36+
hours, err := strconv.Atoi(before)
3737
*l = TTL(time.Duration(hours) * time.Hour)
3838
return err
3939
}
40-
if strings.HasSuffix(value, "m") {
41-
minutes, err := strconv.Atoi(strings.TrimSuffix(value, "m"))
40+
if before, ok := strings.CutSuffix(value, "m"); ok {
41+
minutes, err := strconv.Atoi(before)
4242
*l = TTL(time.Duration(minutes) * time.Minute)
4343
return err
4444
}
45-
if strings.HasSuffix(value, "s") {
46-
seconds, err := strconv.Atoi(strings.TrimSuffix(value, "s"))
45+
if before, ok := strings.CutSuffix(value, "s"); ok {
46+
seconds, err := strconv.Atoi(before)
4747
*l = TTL(time.Duration(seconds) * time.Second)
4848
return err
4949
}

errors/errors.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func New(code string, message string) error {
4242
}
4343

4444
// Errorf returns an error and formats according to a format specifier
45-
func Errorf(code string, format string, args ...interface{}) error {
45+
func Errorf(code string, format string, args ...any) error {
4646
return New(code, fmt.Sprintf(format, args...))
4747
}
4848

@@ -52,7 +52,7 @@ func InternalError(message string) error {
5252
}
5353

5454
// InternalErrorf is a convenience function to format an Internal error
55-
func InternalErrorf(format string, args ...interface{}) error {
55+
func InternalErrorf(format string, args ...any) error {
5656
return Errorf(CodeInternal, format, args...)
5757
}
5858

@@ -65,7 +65,7 @@ func InternalWrapError(err error, message ...string) error {
6565
}
6666

6767
// InternalWrapErrorf annotates the error with the ERR_INTERNAL code and a stack trace, optional message
68-
func InternalWrapErrorf(err error, format string, args ...interface{}) error {
68+
func InternalWrapErrorf(err error, format string, args ...any) error {
6969
return Wrap(err, CodeInternal, fmt.Sprintf(format, args...))
7070
}
7171

hack/api/jsonschema/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func main() {
4242
"$id": "https://raw.githubusercontent.com/argoproj/argo-workflows/HEAD/api/jsonschema/schema.json",
4343
"$schema": "https://json-schema.org/draft/2020-12/schema",
4444
"type": "object",
45-
"oneOf": []interface{}{
45+
"oneOf": []any{
4646
obj{"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.ClusterWorkflowTemplate"},
4747
obj{"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.CronWorkflow"},
4848
obj{"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Workflow"},

0 commit comments

Comments
 (0)