Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scopelint reports false positives #281

Closed
zlozano opened this issue Nov 7, 2018 · 5 comments
Closed

scopelint reports false positives #281

zlozano opened this issue Nov 7, 2018 · 5 comments

Comments

@zlozano
Copy link

zlozano commented Nov 7, 2018

I recently pulled down the latest golangci-lint, and it is reporting false positives for scopelint on my table test. e.g.

   func TestSomething(t *testing.T) {
        tc := []struct {
		Name        string
		Expected  string
	}{
		{
			Name:       "foo",
			Expected: "bar",
		},
		{
			Name:       "fizz",
			Expected: "buzz",
		},
	}

	for _, tt := range tc {
		t.Run(tt.Name, func(t *testing.T) {
			result := thingUnderTest(...)
                         if result != tt.Expected {
                             t.Fatal("failed.")
                         }
		})
	}
   }

In this case since the testing closure is executed immediately in the same iteration, the mistake discussed here: https://github.com/golang/go/wiki/CommonMistakes is not relevant.

@powerman
Copy link

powerman commented Nov 9, 2018

Another example of same issue:

for _, val := range vals {
    i := sort.Search(…, func(i int) bool { … val … })
}

Probably same happens with sort.Slice but I didn't tested this.

@jirfag
Copy link
Member

jirfag commented Nov 10, 2018

hi!
does it reproduce with only scopelint? Or is it golangci-lint-only issue?

@powerman
Copy link

Yes, it does reproduce.

@cloudlena
Copy link

I just created an issue for scopelint. I think this one here can be closed because it's not a golangci-lint issue.

@jirfag
Copy link
Member

jirfag commented Nov 12, 2018

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants