sivchari / tenv

tenv detects environment variable not using t.Setenv
MIT License
23 stars 7 forks source link

Add support for detecting issues within for loops #33

Closed crobert-1 closed 5 months ago

crobert-1 commented 10 months ago

I added the following test here, and no errors or issues are displayed:

func TestForLoop(t *testing.T) {
    testsetup()
    for i := 0; i < 3; i++ {
        os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `f\\.Setenv\\(\\)` in TestForLoop"
    }
}

The real use case of a for loop would most often be a map of key:value pairs, but a simple loop exposes the lack of issues being reported.

I believe this should be detected and reported as an error in lint.

sivchari commented 5 months ago

Hi, @crobert-1 Sorry for the late reply. I'll take the time on weekend to fix this problem.

sivchari commented 5 months ago

Hi, @coadler . I supported this case, thanks.

crobert-1 commented 5 months ago

Thanks @sivchari, really appreciate your help here!