ldez / usetesting

Detects when some calls can be replaced by methods from the testing package
Apache License 2.0
12 stars 0 forks source link

support os.CreateTemp internally using os.TempDir() in some cases #1

Open ccoVeille opened 5 hours ago

ccoVeille commented 5 hours ago

You could check for os.CreateTemp using empty string as first parameter, will lead to call os.TempDir(), so it can be replaced by t.TmpDir

https://cs.opensource.google/go/go/+/refs/tags/go1.23.3:src/os/tempfile.go;l=35-38

I identified it by working on

I added myself a TODO to check if I could do it later, but I didn't. And your linter is a perfect candidate.

The pattern is widely used

https://github.com/search?q=language%3Ago+%22os.CreateTemp%28%5C%22%5C%22%22+path%3A_test.go&type=code

ldez commented 5 hours ago

I already think about that. The approach that just detects all os.CreateTemp will lead to false positives. So the cases should be exact to be accurate. I have some ideas around that, but not for this first version.