Lint: Fix violations of non-constant format string in call (#14974)

* Fix violations of non-constant format string in call

* Changelog fragment
This commit is contained in:
Preston Van Loon
2025-02-21 13:46:19 -06:00
committed by GitHub
parent 9bceaa59d2
commit 014dbd5c3a
18 changed files with 35 additions and 45 deletions

View File

@@ -47,10 +47,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
case token.EQL, token.NEQ, token.GEQ, token.LEQ, token.GTR, token.LSS:
var xBuf, yBuf bytes.Buffer
if err := printer.Fprint(&xBuf, pass.Fset, expr.X); err != nil {
pass.Reportf(expr.X.Pos(), err.Error())
pass.Reportf(expr.X.Pos(), "error=%s", err)
}
if err := printer.Fprint(&yBuf, pass.Fset, expr.Y); err != nil {
pass.Reportf(expr.Y.Pos(), err.Error())
pass.Reportf(expr.Y.Pos(), "error=%s", err)
}
if xBuf.String() == yBuf.String() {
switch expr.Op {

View File

@@ -4,7 +4,6 @@ package cryptorand
import (
"errors"
"fmt"
"go/ast"
"strings"
@@ -62,8 +61,8 @@ func run(pass *analysis.Pass) (interface{}, error) {
for pkg, path := range aliases {
for _, fn := range disallowedFns {
if isPkgDot(stmt.Fun, pkg, fn) {
pass.Reportf(node.Pos(), fmt.Sprintf(
"%s: %s.%s() (from %s)", errWeakCrypto.Error(), pkg, fn, path))
pass.Reportf(node.Pos(),
"%s: %s.%s() (from %s)", errWeakCrypto.Error(), pkg, fn, path)
}
}
}

View File

@@ -35,7 +35,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
inspection.Preorder(nodeFilter, func(node ast.Node) {
if s, ok := node.(*ast.StructType); ok {
if err := malign(node.Pos(), pass.TypesInfo.Types[s].Type.(*types.Struct)); err != nil {
pass.Reportf(node.Pos(), err.Error())
pass.Reportf(node.Pos(), "error=%s", err)
}
}
})

View File

@@ -6,7 +6,6 @@ package properpermissions
import (
"errors"
"fmt"
"go/ast"
"golang.org/x/tools/go/analysis"
@@ -75,13 +74,11 @@ func run(pass *analysis.Pass) (interface{}, error) {
if isPkgDot(stmt.Fun, alias, fn) {
pass.Reportf(
node.Pos(),
fmt.Sprintf(
"%v: %s.%s() (from %s)",
errUnsafePackage,
alias,
fn,
pkg,
),
"%v: %s.%s() (from %s)",
errUnsafePackage,
alias,
fn,
pkg,
)
}
}

View File

@@ -236,30 +236,24 @@ func checkForRecLocks(node ast.Node, pass *analysis.Pass, inspect *inspector.Ins
if lockTracker.rLockSelector.isRelated(selMap, 0) {
pass.Reportf(
node.Pos(),
fmt.Sprintf(
"%v",
errNestedMixedLock,
),
"%v",
errNestedMixedLock,
)
}
if lockTracker.rLockSelector.isEqual(selMap, 0) {
pass.Reportf(
node.Pos(),
fmt.Sprintf(
"%v",
lockmode.ErrorFound(),
),
"%v",
lockmode.ErrorFound(),
)
} else {
if stack := hasNestedlock(lockTracker.rLockSelector, lockTracker.goroutinePos, selMap, call, inspect, pass, make(map[string]bool),
lockmode.UnLockName()); stack != "" {
pass.Reportf(
node.Pos(),
fmt.Sprintf(
"%v\n%v",
lockmode.ErrorFound(),
stack,
),
"%v\n%v",
lockmode.ErrorFound(),
stack,
)
}
}