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

False positive "ranges should only be cuddled with assignments used in the iteration" #161

Closed
utherbit opened this issue Jan 13, 2025 · 2 comments

Comments

@utherbit
Copy link

This works correctly, and does not interfere with the following code

func init() {
	foo := make([]int, 0, 10)
	for i := 0; i < 10; i++ {
		foo = append(foo, i)
	}
}

but it complains when I do something before the assignment

func init() {
	foo := make([]int, 0, 10)
	for i := 0; i < 10; i++ {
		_ = 1
		foo = append(foo, i)
	}
}

I get:

for statements should only be cuddled with assignments used in the iteration (wsl)
        for i := 0; i < 10; i++ {
        ^

I'm not happy with this, I don't want to separate this assignment from the for loop

@bombsimon
Copy link
Owner

This looks like a duplicate of #24. The issue is that we only check the first statement in the block in addition to the line above. It's only mentioned for range in the docs but is true for every block.

The linked ticket suggest to allow for anywhere in the block. I'm currently working on a rewrite and just implemented this but I don't know when that will be released.

@bombsimon
Copy link
Owner

Closing this, let's discuss in #24 if you want to add more context, details or features.

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

2 participants