Skip to content

Commit c875790

Browse files
committed
Fix lint: Reportf expects string constant
``` printf: non-constant format string in call to (*golang.org/x/tools/go/analysis.Pass).Reportf (govet) ```
1 parent f969f7e commit c875790

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkg/analyzer/analyzer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
2929
callExpr := node.(*ast.CallExpr)
3030
if p, f, ok := getCallExprFunction(callExpr); ok && p == "fmt" && f == "Sprintf" {
3131
if err := checkForHostPortConstruction(callExpr); err != nil {
32-
pass.Reportf(node.Pos(), err.Error())
32+
pass.Reportf(node.Pos(), "%s", err.Error())
3333
}
3434
}
3535
})
@@ -52,7 +52,7 @@ func getCallExprFunction(callExpr *ast.CallExpr) (pkg string, fn string, result
5252

5353
// getStringLiteral returns the value at a position if it's a string literal.
5454
func getStringLiteral(args []ast.Expr, pos int) (string, bool) {
55-
if len(args) < pos + 1 {
55+
if len(args) < pos+1 {
5656
return "", false
5757
}
5858

@@ -72,9 +72,9 @@ func getStringLiteral(args []ast.Expr, pos int) (string, bool) {
7272
// essentially scheme://%s:<something else>, or scheme://user:pass@%s:<something else>.
7373
//
7474
// Matching requirements:
75-
// - Scheme as per RFC3986 is ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
76-
// - A format string substitution in the host portion, preceded by an optional username/password@
77-
// - A colon indicating a port will be specified
75+
// - Scheme as per RFC3986 is ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
76+
// - A format string substitution in the host portion, preceded by an optional username/password@
77+
// - A colon indicating a port will be specified
7878
func checkForHostPortConstruction(sprintf *ast.CallExpr) error {
7979
fs, ok := getStringLiteral(sprintf.Args, 0)
8080
if !ok {
@@ -93,4 +93,4 @@ func checkForHostPortConstruction(sprintf *ast.CallExpr) error {
9393
}
9494

9595
return nil
96-
}
96+
}

0 commit comments

Comments
 (0)