From c97c816133b42257d0bcf1ee4bd178bb2a7a2b9e Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Tue, 10 Sep 2024 12:16:33 +0200 Subject: vendor: update --- vendor/github.com/sivchari/tenv/README.md | 12 +++++------ vendor/github.com/sivchari/tenv/tenv.go | 33 ++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 7 deletions(-) (limited to 'vendor/github.com/sivchari') diff --git a/vendor/github.com/sivchari/tenv/README.md b/vendor/github.com/sivchari/tenv/README.md index c5d004773..56389e2dd 100644 --- a/vendor/github.com/sivchari/tenv/README.md +++ b/vendor/github.com/sivchari/tenv/README.md @@ -1,6 +1,6 @@ # tenv -![tenv Gopher](./tenv.png "Gopher") +tenv Gopher [![test_and_lint](https://github.com/sivchari/tenv/actions/workflows/workflows.yml/badge.svg?branch=main)](https://github.com/sivchari/tenv/actions/workflows/workflows.yml) @@ -10,7 +10,7 @@ tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 ## Instruction ```sh -go install github.com/sivchari/tenv/cmd/tenv +go install github.com/sivchari/tenv/cmd/tenv@latest ``` ## Usage @@ -39,7 +39,7 @@ func helper() { ``` ```console -go vet -vettool=(which tenv) ./... +go vet -vettool=$(which tenv) ./... # a ./main_test.go:11:2: os.Setenv() can be replaced by `t.Setenv()` in TestMain @@ -75,7 +75,7 @@ func helper() { ``` ```console -go vet -vettool=(which tenv) -tenv.all ./... +go vet -vettool=$(which tenv) -tenv.all ./... # a ./main_test.go:11:2: os.Setenv() can be replaced by `t.Setenv()` in TestMain @@ -89,7 +89,7 @@ go vet -vettool=(which tenv) -tenv.all ./... ```yaml - run: name: install tenv - command: go install github.com/sivchari/tenv + command: go install github.com/sivchari/tenv@latest - run: name: run tenv @@ -100,7 +100,7 @@ go vet -vettool=(which tenv) -tenv.all ./... ```yaml - name: install tenv - run: go install github.com/sivchari/tenv + run: go install github.com/sivchari/tenv@latest - name: run tenv run: go vet -vettool=`which tenv` ./... diff --git a/vendor/github.com/sivchari/tenv/tenv.go b/vendor/github.com/sivchari/tenv/tenv.go index fcff98d05..999c5289d 100644 --- a/vendor/github.com/sivchari/tenv/tenv.go +++ b/vendor/github.com/sivchari/tenv/tenv.go @@ -81,6 +81,8 @@ func checkStmts(pass *analysis.Pass, stmts []ast.Stmt, funcName, argName string) if !checkAssignStmt(pass, stmt, funcName, argName) { continue } + case *ast.ForStmt: + checkForStmt(pass, stmt, funcName, argName) } } } @@ -90,6 +92,7 @@ func checkExprStmt(pass *analysis.Pass, stmt *ast.ExprStmt, funcName, argName st if !ok { return false } + checkArgs(pass, callExpr.Args, funcName, argName) fun, ok := callExpr.Fun.(*ast.SelectorExpr) if !ok { return false @@ -108,6 +111,30 @@ func checkExprStmt(pass *analysis.Pass, stmt *ast.ExprStmt, funcName, argName st return true } +func checkArgs(pass *analysis.Pass, args []ast.Expr, funcName, argName string) { + for _, arg := range args { + callExpr, ok := arg.(*ast.CallExpr) + if !ok { + continue + } + fun, ok := callExpr.Fun.(*ast.SelectorExpr) + if !ok { + continue + } + x, ok := fun.X.(*ast.Ident) + if !ok { + continue + } + targetName := x.Name + "." + fun.Sel.Name + if targetName == "os.Setenv" { + if argName == "" { + argName = "testing" + } + pass.Reportf(arg.Pos(), "os.Setenv() can be replaced by `%s.Setenv()` in %s", argName, funcName) + } + } +} + func checkIfStmt(pass *analysis.Pass, stmt *ast.IfStmt, funcName, argName string) bool { assignStmt, ok := stmt.Init.(*ast.AssignStmt) if !ok { @@ -158,6 +185,10 @@ func checkAssignStmt(pass *analysis.Pass, stmt *ast.AssignStmt, funcName, argNam return true } +func checkForStmt(pass *analysis.Pass, stmt *ast.ForStmt, funcName, argName string) { + checkStmts(pass, stmt.Body.List, funcName, argName) +} + func targetRunner(params []*ast.Field, fileName string) (string, bool) { for _, p := range params { switch typ := p.Type.(type) { @@ -196,7 +227,7 @@ func checkStarExprTarget(typ *ast.StarExpr) bool { } targetName := x.Name + "." + selector.Sel.Name switch targetName { - case "testing.T", "testing.B", "testing.F": + case "testing.T", "testing.B": return true default: return false -- cgit mrf-deployment