-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
307 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//golangcitest:args -Eusetesting | ||
package testdata | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_osMkdirTemp(t *testing.T) { | ||
os.MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+` | ||
} | ||
|
||
func Test_osSetenv(t *testing.T) { | ||
os.Setenv("", "") | ||
} | ||
|
||
func Test_osTempDir(t *testing.T) { | ||
os.TempDir() | ||
} | ||
|
||
func Test_osCreateTemp(t *testing.T) { | ||
os.CreateTemp("", "") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+` | ||
os.CreateTemp("", "xx") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+` | ||
os.CreateTemp(os.TempDir(), "xx") | ||
os.CreateTemp(t.TempDir(), "xx") | ||
} |
27 changes: 27 additions & 0 deletions
27
pkg/golinters/usetesting/testdata/usetesting_configuration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//golangcitest:args -Eusetesting | ||
//golangcitest:config_path testdata/usetesting_configuration.yml | ||
package testdata | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_osMkdirTemp(t *testing.T) { | ||
os.MkdirTemp("", "") | ||
} | ||
|
||
func Test_osTempDir(t *testing.T) { | ||
os.TempDir() // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+` | ||
} | ||
|
||
func Test_osSetenv(t *testing.T) { | ||
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+` | ||
} | ||
|
||
func Test_osCreateTemp(t *testing.T) { | ||
os.CreateTemp("", "") | ||
os.CreateTemp("", "xx") | ||
os.CreateTemp(os.TempDir(), "xx") // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+` | ||
os.CreateTemp(t.TempDir(), "xx") | ||
} |
9 changes: 9 additions & 0 deletions
9
pkg/golinters/usetesting/testdata/usetesting_configuration.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
linters-settings: | ||
usetesting: | ||
os-create-temp: false | ||
os-mkdir-temp: false | ||
os-setenv: true | ||
os-temp-dir: true | ||
os-chdir: false | ||
context-background: false | ||
context-todo: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//go:build go1.24 | ||
|
||
//golangcitest:args -Eusetesting | ||
package testdata | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_contextBackground(t *testing.T) { | ||
context.Background() // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+` | ||
} | ||
|
||
func Test_contextTODO(t *testing.T) { | ||
context.TODO() // want `context\.TODO\(\) could be replaced by t\.Context\(\) in .+` | ||
} | ||
|
||
func Test_osChdir(t *testing.T) { | ||
os.Chdir("") // want `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+` | ||
} | ||
|
||
func Test_osMkdirTemp(t *testing.T) { | ||
os.MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+` | ||
} | ||
|
||
func Test_osSetenv(t *testing.T) { | ||
os.Setenv("", "") | ||
} | ||
|
||
func Test_osTempDir(t *testing.T) { | ||
os.TempDir() | ||
} | ||
|
||
func Test_osCreateTemp(t *testing.T) { | ||
os.CreateTemp("", "") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+` | ||
os.CreateTemp("", "xx") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+` | ||
os.CreateTemp(os.TempDir(), "xx") | ||
os.CreateTemp(t.TempDir(), "xx") | ||
} |
42 changes: 42 additions & 0 deletions
42
pkg/golinters/usetesting/testdata/usetesting_go124_configuration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//go:build go1.24 | ||
|
||
//golangcitest:args -Eusetesting | ||
//golangcitest:config_path testdata/usetesting_go124_configuration.yml | ||
package testdata | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_contextBackground(t *testing.T) { | ||
context.Background() | ||
} | ||
|
||
func Test_contextTODO(t *testing.T) { | ||
context.TODO() | ||
} | ||
|
||
func Test_osChdir(t *testing.T) { | ||
os.Chdir("") | ||
} | ||
|
||
func Test_osMkdirTemp(t *testing.T) { | ||
os.MkdirTemp("", "") | ||
} | ||
|
||
func Test_osSetenv(t *testing.T) { | ||
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+` | ||
} | ||
|
||
func Test_osTempDir(t *testing.T) { | ||
os.TempDir() // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+` | ||
} | ||
|
||
func Test_osCreateTemp(t *testing.T) { | ||
os.CreateTemp("", "") | ||
os.CreateTemp("", "xx") | ||
os.CreateTemp(os.TempDir(), "xx") // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+` | ||
os.CreateTemp(t.TempDir(), "xx") | ||
} |
9 changes: 9 additions & 0 deletions
9
pkg/golinters/usetesting/testdata/usetesting_go124_configuration.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
linters-settings: | ||
usetesting: | ||
os-create-temp: false | ||
os-mkdir-temp: false | ||
os-setenv: true | ||
os-temp-dir: true | ||
os-chdir: false | ||
context-background: false | ||
context-todo: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package usetesting | ||
|
||
import ( | ||
"github.com/ldez/usetesting" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/goanalysis" | ||
) | ||
|
||
func New(settings *config.UseTestingSettings) *goanalysis.Linter { | ||
a := usetesting.NewAnalyzer() | ||
|
||
cfg := make(map[string]map[string]any) | ||
if settings != nil { | ||
cfg[a.Name] = map[string]any{ | ||
"contextbackground": settings.ContextBackground, | ||
"contexttodo": settings.ContextTodo, | ||
"oschdir": settings.OSChdir, | ||
"osmkdirtemp": settings.OSMkdirTemp, | ||
"ossetenv": settings.OSSetenv, | ||
"ostempdir": settings.OSTempDir, | ||
"oscreatetemp": settings.OSCreateTemp, | ||
} | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
a.Name, | ||
a.Doc, | ||
[]*analysis.Analyzer{a}, | ||
cfg, | ||
).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package usetesting | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golangci/golangci-lint/test/testshared/integration" | ||
) | ||
|
||
func TestFromTestdata(t *testing.T) { | ||
integration.RunTestdata(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.