Skip to content

Commit a4a9704

Browse files
committed
improve report message and fix option description
1 parent ec3082f commit a4a9704

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

.golangci.example.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ linters-settings:
628628
begin: true
629629

630630
tenv:
631-
# The all option will run against all method in test file.
632-
# By default, only methods that take *testing.T, *testing.B, and testing.TB as arguments are checked.
631+
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
632+
# By default, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
633633
all: false
634634

635635
unparam:

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ require (
6969
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
7070
github.com/shirou/gopsutil/v3 v3.21.8
7171
github.com/sirupsen/logrus v1.8.1
72-
github.com/sivchari/tenv v1.2.6
72+
github.com/sivchari/tenv v1.3.7
7373
github.com/sonatard/noctx v0.0.1
7474
github.com/sourcegraph/go-diff v0.6.1
7575
github.com/spf13/cobra v1.2.1

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/testdata/tenv_all_test.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,41 @@ import (
88
)
99

1010
var (
11-
e = os.Setenv("a", "b") // ERROR "variable e is not using testing.Setenv"
11+
e = os.Setenv("a", "b") // never seen
1212
)
1313

1414
func setup() {
15-
os.Setenv("a", "b") // ERROR "func setup is not using testing.Setenv"
16-
err := os.Setenv("a", "b") // ERROR "func setup is not using testing.Setenv"
17-
if err != nil {
15+
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup"
16+
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup"
17+
_ = err
18+
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup"
1819
_ = err
1920
}
2021
}
2122

2223
func TestF(t *testing.T) {
23-
os.Setenv("a", "b") // ERROR "func TestF is not using testing.Setenv"
24-
if err := os.Setenv("a", "b"); err != nil { // ERROR "func TestF is not using testing.Setenv"
24+
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF"
25+
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF"
26+
_ = err
27+
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF"
2528
_ = err
2629
}
2730
}
2831

2932
func BenchmarkF(b *testing.B) {
30-
os.Setenv("a", "b") // ERROR "func BenchmarkF is not using testing.Setenv"
31-
if err := os.Setenv("a", "b"); err != nil { // ERROR "func BenchmarkF is not using testing.Setenv"
33+
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF"
34+
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF"
35+
_ = err
36+
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF"
3237
_ = err
3338
}
3439
}
3540

3641
func testTB(tb testing.TB) {
37-
os.Setenv("a", "b") // ERROR "func testTB is not using testing.Setenv"
38-
if err := os.Setenv("a", "b"); err != nil { // ERROR "func testTB is not using testing.Setenv"
42+
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB"
43+
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB"
44+
_ = err
45+
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB"
3946
_ = err
4047
}
4148
}

test/testdata/tenv_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
var (
10-
e = os.Setenv("a", "b") // OK
10+
e = os.Setenv("a", "b") // never seen
1111
)
1212

1313
func setup() {
@@ -19,22 +19,22 @@ func setup() {
1919
}
2020

2121
func TestF(t *testing.T) {
22-
os.Setenv("a", "b") // ERROR "func TestF is not using testing.Setenv"
23-
if err := os.Setenv("a", "b"); err != nil { // ERROR "func TestF is not using testing.Setenv"
22+
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF"
23+
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF"
2424
_ = err
2525
}
2626
}
2727

2828
func BenchmarkF(b *testing.B) {
29-
os.Setenv("a", "b") // ERROR "func BenchmarkF is not using testing.Setenv"
30-
if err := os.Setenv("a", "b"); err != nil { // ERROR "func BenchmarkF is not using testing.Setenv"
29+
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF"
30+
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF"
3131
_ = err
3232
}
3333
}
3434

3535
func testTB(tb testing.TB) {
36-
os.Setenv("a", "b") // ERROR "func testTB is not using testing.Setenv"
37-
if err := os.Setenv("a", "b"); err != nil { // ERROR "func testTB is not using testing.Setenv"
36+
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB"
37+
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB"
3838
_ = err
3939
}
4040
}

0 commit comments

Comments
 (0)