Skip to content

Commit 40944ea

Browse files
committed
feat: v0.2.0
1 parent 2ee4944 commit 40944ea

12 files changed

+99
-27
lines changed

.golangci.next.reference.yml

+19-11
Original file line numberDiff line numberDiff line change
@@ -3536,28 +3536,36 @@ linters-settings:
35363536
constant-kind: true
35373537

35383538
usetesting:
3539-
# Enable/disable `context.Background()` detections.
3540-
# Disabled if Go < 1.24.
3539+
# Enable/disable `os.CreateTemp("", ...)` detections.
35413540
# Default: true
3542-
context-background: false
3541+
os-create-temp: false
35433542

3544-
# Enable/disable `context.TODO()` detections.
3545-
# Disabled if Go < 1.24.
3543+
# Enable/disable `os.MkdirTemp()` detections.
35463544
# Default: true
3547-
context-todo: false
3545+
os-mkdir-temp: false
3546+
3547+
# Enable/disable `os.Setenv()` detections.
3548+
# Default: false
3549+
os-setenv: true
3550+
3551+
# Enable/disable `os.TempDir()` detections.
3552+
# Default: false
3553+
os-temp-dir: true
35483554

35493555
# Enable/disable `os.Chdir()` detections.
35503556
# Disabled if Go < 1.24.
35513557
# Default: true
35523558
os-chdir: false
35533559

3554-
# Enable/disable `os.MkdirTemp()` detections.
3560+
# Enable/disable `context.Background()` detections.
3561+
# Disabled if Go < 1.24.
35553562
# Default: true
3556-
os-mkdir-temp: false
3563+
context-background: false
35573564

3558-
# Enable/disable `os.Setenv()` detections.
3559-
# Default: false
3560-
os-setenv: true
3565+
# Enable/disable `context.TODO()` detections.
3566+
# Disabled if Go < 1.24.
3567+
# Default: true
3568+
context-todo: false
35613569

35623570
unconvert:
35633571
# Remove conversions that force intermediate rounding.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ require (
6868
github.com/lasiar/canonicalheader v1.1.2
6969
github.com/ldez/gomoddirectives v0.2.4
7070
github.com/ldez/tagliatelle v0.6.0
71-
github.com/ldez/usetesting v0.1.0
71+
github.com/ldez/usetesting v0.2.0
7272
github.com/leonklingele/grouper v1.1.2
7373
github.com/macabu/inamedparam v0.1.3
7474
github.com/maratori/testableexamples v1.0.0

go.sum

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

jsonschema/golangci.next.jsonschema.json

+9
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@
428428
"unparam",
429429
"unused",
430430
"usestdlibvars",
431+
"usetesting",
431432
"varnamelen",
432433
"wastedassign",
433434
"whitespace",
@@ -3348,6 +3349,14 @@
33483349
"os-setenv": {
33493350
"type": "boolean",
33503351
"default": false
3352+
},
3353+
"os-create-temp": {
3354+
"type": "boolean",
3355+
"default": true
3356+
},
3357+
"os-temp-dir": {
3358+
"type": "boolean",
3359+
"default": false
33513360
}
33523361
}
33533362
},

pkg/config/linters_settings.go

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ var defaultLintersSettings = LintersSettings{
184184
ContextTodo: true,
185185
OSChdir: true,
186186
OSMkdirTemp: true,
187+
OSSetenv: false,
188+
OSTempDir: false,
189+
OSSCreateTemp: true,
187190
},
188191
Varnamelen: VarnamelenSettings{
189192
MaxDistance: 5,
@@ -972,6 +975,8 @@ type UseTestingSettings struct {
972975
OSChdir bool `mapstructure:"os-chdir"`
973976
OSMkdirTemp bool `mapstructure:"os-mkdir-temp"`
974977
OSSetenv bool `mapstructure:"os-setenv"`
978+
OSTempDir bool `mapstructure:"os-temp-dir"`
979+
OSSCreateTemp bool `mapstructure:"os-create-temp"`
975980
}
976981

977982
type UnconvertSettings struct {

pkg/golinters/usetesting/testdata/usetesting.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@ import (
77
)
88

99
func Test_osMkdirTemp(t *testing.T) {
10-
os.MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by <t/b/tb>\.TempDir\(\) in .+`
10+
os.MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+`
1111
}
1212

1313
func Test_osSetenv(t *testing.T) {
1414
os.Setenv("", "")
1515
}
16+
17+
func Test_osTempDir(t *testing.T) {
18+
os.TempDir()
19+
}
20+
21+
func Test_osCreateTemp(t *testing.T) {
22+
os.CreateTemp("", "") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+`
23+
os.CreateTemp("", "xx") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+`
24+
os.CreateTemp(os.TempDir(), "xx")
25+
os.CreateTemp(t.TempDir(), "xx")
26+
}

pkg/golinters/usetesting/testdata/usetesting_configuration.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ func Test_osMkdirTemp(t *testing.T) {
1111
os.MkdirTemp("", "")
1212
}
1313

14+
func Test_osTempDir(t *testing.T) {
15+
os.TempDir() // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+`
16+
}
17+
1418
func Test_osSetenv(t *testing.T) {
15-
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by <t/b/tb>\.Setenv\(\) in .+`
19+
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+`
20+
}
21+
22+
func Test_osCreateTemp(t *testing.T) {
23+
os.CreateTemp("", "")
24+
os.CreateTemp("", "xx")
25+
os.CreateTemp(os.TempDir(), "xx") // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+`
26+
os.CreateTemp(t.TempDir(), "xx")
1627
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
linters-settings:
22
usetesting:
3-
context-background: false
4-
context-todo: false
5-
os-chdir: false
3+
os-create-temp: false
64
os-mkdir-temp: false
75
os-setenv: true
6+
os-temp-dir: true
7+
os-chdir: false
8+
context-background: false
9+
context-todo: false

pkg/golinters/usetesting/testdata/usetesting_go124.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,32 @@ import (
1010
)
1111

1212
func Test_contextBackground(t *testing.T) {
13-
context.Background() // want `context\.Background\(\) could be replaced by <t/b/tb>\.Context\(\) in .+`
13+
context.Background() // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
1414
}
1515

1616
func Test_contextTODO(t *testing.T) {
17-
context.TODO() // want `context\.TODO\(\) could be replaced by <t/b/tb>\.Context\(\) in .+`
17+
context.TODO() // want `context\.TODO\(\) could be replaced by t\.Context\(\) in .+`
1818
}
1919

2020
func Test_osChdir(t *testing.T) {
21-
os.Chdir("") // want `os\.Chdir\(\) could be replaced by <t/b/tb>\.Chdir\(\) in .+`
21+
os.Chdir("") // want `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+`
2222
}
2323

2424
func Test_osMkdirTemp(t *testing.T) {
25-
os.MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by <t/b/tb>\.TempDir\(\) in .+`
25+
os.MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+`
2626
}
2727

2828
func Test_osSetenv(t *testing.T) {
2929
os.Setenv("", "")
3030
}
31+
32+
func Test_osTempDir(t *testing.T) {
33+
os.TempDir()
34+
}
35+
36+
func Test_osCreateTemp(t *testing.T) {
37+
os.CreateTemp("", "") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+`
38+
os.CreateTemp("", "xx") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+`
39+
os.CreateTemp(os.TempDir(), "xx")
40+
os.CreateTemp(t.TempDir(), "xx")
41+
}

pkg/golinters/usetesting/testdata/usetesting_go124_configuration.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,16 @@ func Test_osMkdirTemp(t *testing.T) {
2727
}
2828

2929
func Test_osSetenv(t *testing.T) {
30-
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by <t/b/tb>\.Setenv\(\) in .+`
30+
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+`
31+
}
32+
33+
func Test_osTempDir(t *testing.T) {
34+
os.TempDir() // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+`
35+
}
36+
37+
func Test_osCreateTemp(t *testing.T) {
38+
os.CreateTemp("", "")
39+
os.CreateTemp("", "xx")
40+
os.CreateTemp(os.TempDir(), "xx") // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+`
41+
os.CreateTemp(t.TempDir(), "xx")
3142
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
linters-settings:
22
usetesting:
3-
context-background: false
4-
context-todo: false
5-
os-chdir: false
3+
os-create-temp: false
64
os-mkdir-temp: false
75
os-setenv: true
6+
os-temp-dir: true
7+
os-chdir: false
8+
context-background: false
9+
context-todo: false

pkg/golinters/usetesting/usetesting.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func New(settings *config.UseTestingSettings) *goanalysis.Linter {
1919
"oschdir": settings.OSChdir,
2020
"osmkdirtemp": settings.OSMkdirTemp,
2121
"ossetenv": settings.OSSetenv,
22+
"ostempdir": settings.OSTempDir,
23+
"oscreatetemp": settings.OSSCreateTemp,
2224
}
2325
}
2426

0 commit comments

Comments
 (0)