From a98b1b6fe55ac48a0e8a119f479c39fa42fdf5e6 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Wed, 19 Jul 2023 16:58:31 +0800 Subject: [PATCH] chore: unnecessary use of fmt.Sprintf Signed-off-by: guoguangwu --- pkg/schema/annotations.go | 38 ++++++++++++------------- pkg/template/compiled_template_error.go | 2 +- pkg/validations/validate.go | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/schema/annotations.go b/pkg/schema/annotations.go index bcaf6b27..c517532b 100644 --- a/pkg/schema/annotations.go +++ b/pkg/schema/annotations.go @@ -166,7 +166,7 @@ func NewDeprecatedAnnotation(ann template.NodeAnnotation, pos *filepos.Position) annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationDeprecated), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("keyword argument in @%v (by %v)", AnnotationDeprecated, ann.Position.AsCompactString()), hints: []string{"this annotation only accepts one argument: a string."}, } @@ -177,7 +177,7 @@ func NewDeprecatedAnnotation(ann template.NodeAnnotation, pos *filepos.Position) annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationDeprecated), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("missing value in @%v (by %v)", AnnotationDeprecated, ann.Position.AsCompactString()), } case numArgs > 1: @@ -185,7 +185,7 @@ func NewDeprecatedAnnotation(ann template.NodeAnnotation, pos *filepos.Position) annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationDeprecated), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("%v values in @%v (by %v)", numArgs, AnnotationDeprecated, ann.Position.AsCompactString()), } } @@ -196,7 +196,7 @@ func NewDeprecatedAnnotation(ann template.NodeAnnotation, pos *filepos.Position) annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationDeprecated), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("Non-string value in @%v (by %v)", AnnotationDeprecated, ann.Position.AsCompactString()), } } @@ -251,7 +251,7 @@ func NewDescriptionAnnotation(ann template.NodeAnnotation, pos *filepos.Position annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationDescription), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("keyword argument in @%v (by %v)", AnnotationDescription, ann.Position.AsCompactString()), hints: []string{"this annotation only accepts one argument: a string."}, } @@ -262,7 +262,7 @@ func NewDescriptionAnnotation(ann template.NodeAnnotation, pos *filepos.Position annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationDescription), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("missing value in @%v (by %v)", AnnotationDescription, ann.Position.AsCompactString()), } case numArgs > 1: @@ -270,7 +270,7 @@ func NewDescriptionAnnotation(ann template.NodeAnnotation, pos *filepos.Position annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationDescription), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("%v values in @%v (by %v)", numArgs, AnnotationDescription, ann.Position.AsCompactString()), } } @@ -281,7 +281,7 @@ func NewDescriptionAnnotation(ann template.NodeAnnotation, pos *filepos.Position annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationDescription), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("Non-string value in @%v (by %v)", AnnotationDescription, ann.Position.AsCompactString()), } } @@ -295,7 +295,7 @@ func NewTitleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (*Ti annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationTitle), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("keyword argument in @%v (by %v)", AnnotationTitle, ann.Position.AsCompactString()), hints: []string{"this annotation only accepts one argument: a string."}, } @@ -306,7 +306,7 @@ func NewTitleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (*Ti annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationTitle), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("missing value in @%v (by %v)", AnnotationTitle, ann.Position.AsCompactString()), } case numArgs > 1: @@ -314,7 +314,7 @@ func NewTitleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (*Ti annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationTitle), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("%v values in @%v (by %v)", numArgs, AnnotationTitle, ann.Position.AsCompactString()), } } @@ -325,7 +325,7 @@ func NewTitleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (*Ti annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationTitle), - expected: fmt.Sprintf("string"), + expected: "string", found: fmt.Sprintf("Non-string value in @%v (by %v)", AnnotationTitle, ann.Position.AsCompactString()), } } @@ -339,7 +339,7 @@ func NewExampleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (* annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationExamples), - expected: fmt.Sprintf("2-tuple containing description (string) and example value (of expected type)"), + expected: "2-tuple containing description (string) and example value (of expected type)", found: fmt.Sprintf("keyword argument in @%v (by %v)", AnnotationExamples, ann.Position.AsCompactString()), } } @@ -348,7 +348,7 @@ func NewExampleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (* annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationExamples), - expected: fmt.Sprintf("2-tuple containing description (string) and example value (of expected type)"), + expected: "2-tuple containing description (string) and example value (of expected type)", found: fmt.Sprintf("missing value in @%v (by %v)", AnnotationExamples, ann.Position.AsCompactString()), } } @@ -361,7 +361,7 @@ func NewExampleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (* annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationExamples), - expected: fmt.Sprintf("2-tuple containing description (string) and example value (of expected type)"), + expected: "2-tuple containing description (string) and example value (of expected type)", found: fmt.Sprintf("%v for @%v (at %v)", ex.Type(), AnnotationExamples, ann.Position.AsCompactString()), } } @@ -371,7 +371,7 @@ func NewExampleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (* annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationExamples), - expected: fmt.Sprintf("2-tuple containing description (string) and example value (of expected type)"), + expected: "2-tuple containing description (string) and example value (of expected type)", found: fmt.Sprintf("empty tuple in @%v (by %v)", AnnotationExamples, ann.Position.AsCompactString()), } case len(exampleTuple) == 1: @@ -379,7 +379,7 @@ func NewExampleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (* annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationExamples), - expected: fmt.Sprintf("2-tuple containing description (string) and example value (of expected type)"), + expected: "2-tuple containing description (string) and example value (of expected type)", found: fmt.Sprintf("empty tuple in @%v (by %v)", AnnotationExamples, ann.Position.AsCompactString()), } case len(exampleTuple) > 2: @@ -387,7 +387,7 @@ func NewExampleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (* annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationExamples), - expected: fmt.Sprintf("2-tuple containing description (string) and example value (of expected type)"), + expected: "2-tuple containing description (string) and example value (of expected type)", found: fmt.Sprintf("%v-tuple argument in @%v (by %v)", len(exampleTuple), AnnotationExamples, ann.Position.AsCompactString()), } default: @@ -397,7 +397,7 @@ func NewExampleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (* annPositions: []*filepos.Position{ann.Position}, position: pos, description: fmt.Sprintf("syntax error in @%v annotation", AnnotationExamples), - expected: fmt.Sprintf("2-tuple containing description (string) and example value (of expected type)"), + expected: "2-tuple containing description (string) and example value (of expected type)", found: fmt.Sprintf("%v value for @%v (at %v)", exampleTuple[0].Type(), AnnotationExamples, ann.Position.AsCompactString()), } } diff --git a/pkg/template/compiled_template_error.go b/pkg/template/compiled_template_error.go index 8d6edfd4..ef5ce4d4 100644 --- a/pkg/template/compiled_template_error.go +++ b/pkg/template/compiled_template_error.go @@ -123,7 +123,7 @@ func (e CompiledTemplateMultiError) Error() string { } if len(otherLines) > 0 { - result = append(result, []string{"", fmt.Sprintf(" reason:")}...) + result = append(result, []string{"", " reason:"}...) for _, line := range otherLines { result = append(result, fmt.Sprintf(" %s", line)) } diff --git a/pkg/validations/validate.go b/pkg/validations/validate.go index 228ebba0..6194a83e 100644 --- a/pkg/validations/validate.go +++ b/pkg/validations/validate.go @@ -241,7 +241,7 @@ func (v validationKwargs) asRules() []rule { } if v.notNull { rules = append(rules, rule{ - msg: fmt.Sprintf("not null"), + msg: "not null", assertion: yttlibrary.NewAssertNotNull().CheckFunc(), isCritical: true, priority: 100,