Skip to content

Commit

Permalink
chore: unnecessary use of fmt.Sprintf (#862)
Browse files Browse the repository at this point in the history
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
  • Loading branch information
testwill committed Jul 26, 2023
1 parent 9a46950 commit 0e9d793
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
38 changes: 19 additions & 19 deletions pkg/schema/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."},
}
Expand All @@ -177,15 +177,15 @@ 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:
return nil, schemaAssertionError{
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()),
}
}
Expand All @@ -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()),
}
}
Expand Down Expand Up @@ -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."},
}
Expand All @@ -262,15 +262,15 @@ 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:
return nil, schemaAssertionError{
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()),
}
}
Expand All @@ -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()),
}
}
Expand All @@ -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."},
}
Expand All @@ -306,15 +306,15 @@ 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:
return nil, schemaAssertionError{
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()),
}
}
Expand All @@ -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()),
}
}
Expand All @@ -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()),
}
}
Expand All @@ -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()),
}
}
Expand All @@ -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()),
}
}
Expand All @@ -371,23 +371,23 @@ 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:
return nil, schemaAssertionError{
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:
return nil, schemaAssertionError{
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:
Expand All @@ -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()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/template/compiled_template_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/validations/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0e9d793

Please sign in to comment.