aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/sivchari
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-09-10 12:16:33 +0200
committerTaras Madan <tarasmadan@google.com>2024-09-10 14:05:26 +0000
commitc97c816133b42257d0bcf1ee4bd178bb2a7a2b9e (patch)
tree0bcbc2e540bbf8f62f6c17887cdd53b8c2cee637 /vendor/github.com/sivchari
parent54e657429ab892ad06c90cd7c1a4eb33ba93a3dc (diff)
vendor: update
Diffstat (limited to 'vendor/github.com/sivchari')
-rw-r--r--vendor/github.com/sivchari/tenv/README.md12
-rw-r--r--vendor/github.com/sivchari/tenv/tenv.go33
2 files changed, 38 insertions, 7 deletions
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")
+<img title="Gopher" alt="tenv Gopher" src="./tenv.png" width="400">
[![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