Detects when some calls can be replaced by methods from the testing package
Go
34
57 commits
updated Oct 1, 2026
Detects when some calls can be replaced by methods from the testing package.
Recommended.
linters:
enable:
- usetesting
settings:
usetesting:
# Enable/disable `os.CreateTemp("", ...)` detections.
# Default: true
os-create-temp: false
# Enable/disable `os.MkdirTemp()` detections.
# Default: true
os-mkdir-temp: false
# Enable/disable `os.Setenv()` detections.
# Default: true
os-setenv: false
# Enable/disable `os.TempDir()` detections.
# Default: false
os-temp-dir: true
# Enable/disable `os.Chdir()` detections.
# Disabled if Go < 1.24.
# Default: true
os-chdir: false
# Enable/disable `context.Background()` detections.
# Disabled if Go < 1.24.
# Default: false
context-background: true
# Enable/disable `context.TODO()` detections.
# Disabled if Go < 1.24.
# Default: false
context-todo: true
go install github.com/ldez/usetesting/cmd/usetesting@latest
usetesting: Reports uses of functions with replacement inside the testing package.
Usage: usetesting [-flag] [package]
Flags:
-contextbackground
Enable/disable context.Background() detections (default true)
-contexttodo
Enable/disable context.TODO() detections (default true)
-oschdir
Enable/disable os.Chdir() detections (default true)
-osmkdirtemp
Enable/disable os.MkdirTemp() detections (default true)
-ossetenv
Enable/disable os.Setenv() detections (default false)
-ostempdir
Enable/disable os.TempDir() detections (default false)
-oscreatetemp
Enable/disable os.CreateTemp("", ...) detections (default true)
...
os.MkdirTempfunc TestExample(t *testing.T) {
os.MkdirTemp("a", "b")
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
t.TempDir()
// ...
}
os.TempDirfunc TestExample(t *testing.T) {
os.TempDir()
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
t.TempDir()
// ...
}
os.CreateTempfunc TestExample(t *testing.T) {
os.CreateTemp("", "x")
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
os.CreateTemp(t.TempDir(), "x")
// ...
}
os.Setenvfunc TestExample(t *testing.T) {
os.Setenv("A", "b")
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
t.Setenv("A", "b")
// ...
}
os.Chdir (Go >= 1.24)func TestExample(t *testing.T) {
os.Chdir("x")
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
t.Chdir("x")
// ...
}
context.Background (Go >= 1.24)func TestExample(t *testing.T) {
ctx := context.Background()
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
ctx := t.Context()
// ...
}
context.TODO (Go >= 1.24)func TestExample(t *testing.T) {
ctx := context.TODO()
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
ctx := t.Context()
// ...
}
4,633 followers · starred Nov 2024
194 followers · starred Dec 2024
Go
98.4%
Makefile
1.6%
Detects when some calls can be replaced by methods from the testing package
Go
34
57 commits
updated Oct 1, 2026
Detects when some calls can be replaced by methods from the testing package.
Recommended.
linters:
enable:
- usetesting
settings:
usetesting:
# Enable/disable `os.CreateTemp("", ...)` detections.
# Default: true
os-create-temp: false
# Enable/disable `os.MkdirTemp()` detections.
# Default: true
os-mkdir-temp: false
# Enable/disable `os.Setenv()` detections.
# Default: true
os-setenv: false
# Enable/disable `os.TempDir()` detections.
# Default: false
os-temp-dir: true
# Enable/disable `os.Chdir()` detections.
# Disabled if Go < 1.24.
# Default: true
os-chdir: false
# Enable/disable `context.Background()` detections.
# Disabled if Go < 1.24.
# Default: false
context-background: true
# Enable/disable `context.TODO()` detections.
# Disabled if Go < 1.24.
# Default: false
context-todo: true
go install github.com/ldez/usetesting/cmd/usetesting@latest
usetesting: Reports uses of functions with replacement inside the testing package.
Usage: usetesting [-flag] [package]
Flags:
-contextbackground
Enable/disable context.Background() detections (default true)
-contexttodo
Enable/disable context.TODO() detections (default true)
-oschdir
Enable/disable os.Chdir() detections (default true)
-osmkdirtemp
Enable/disable os.MkdirTemp() detections (default true)
-ossetenv
Enable/disable os.Setenv() detections (default false)
-ostempdir
Enable/disable os.TempDir() detections (default false)
-oscreatetemp
Enable/disable os.CreateTemp("", ...) detections (default true)
...
os.MkdirTempfunc TestExample(t *testing.T) {
os.MkdirTemp("a", "b")
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
t.TempDir()
// ...
}
os.TempDirfunc TestExample(t *testing.T) {
os.TempDir()
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
t.TempDir()
// ...
}
os.CreateTempfunc TestExample(t *testing.T) {
os.CreateTemp("", "x")
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
os.CreateTemp(t.TempDir(), "x")
// ...
}
os.Setenvfunc TestExample(t *testing.T) {
os.Setenv("A", "b")
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
t.Setenv("A", "b")
// ...
}
os.Chdir (Go >= 1.24)func TestExample(t *testing.T) {
os.Chdir("x")
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
t.Chdir("x")
// ...
}
context.Background (Go >= 1.24)func TestExample(t *testing.T) {
ctx := context.Background()
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
ctx := t.Context()
// ...
}
context.TODO (Go >= 1.24)func TestExample(t *testing.T) {
ctx := context.TODO()
// ...
}
It can be replaced by:
func TestExample(t *testing.T) {
ctx := t.Context()
// ...
}
4,633 followers · starred Nov 2024
194 followers · starred Dec 2024
Go
98.4%
Makefile
1.6%