-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add noloopclosure #3027
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
feat: add noloopclosure #3027
Conversation
Hey, thank you for opening your first Pull Request ! |
In order for a pull request adding a linter to be reviewed, the linter and the PR must follow some requirements. Pull Request Description
Linter
The Linter Tests Inside Golangci-lint
|
Hello, I feel like a duplicate of exportloopref or looppointer |
Hi @ldez I checked both linters already and it seems that those linters only check whether the loop variable is captured using This new linter checks whether the loop variable is captured using closure or not (not necessarily a pointer) -- to avoid accidental reference because of closures. It will check whether a loop has function literal on it and check whether the function literal's body referenced the loop variable or not (similar to For example, this linter will complain that
I tried both linters that you mentioned for code snippet above and it passes. |
We refused looppointer because of the number of false-positives, you will have to prove that don't have the same problem as looppointer |
@ldez this linter is way simpler than What it does is basically:
The implementation is basically the striped-down version of |
Hi @ldez what kind of proof do you require for this one? |
After reading this similar issue more thoroughly, I think this linter will have the same issue that These two linters will reject a valid Go code that might or might not cause a bug. The idea of these two linter is to disallow a certain practices that might introduce the bug in the first place (so it will be impossible to introduce the bug). So I wouldn't call them a false-positive (from the linter's perspective) since that's the whole point of these two linters. Personally I think this linter will complement @hawkingrei Having said all of that, I don't think this linter will be merged to master anytime soon since it cause issues to users that enables all the linter via @ldez Feel free to close this issue if you think we shouldn't merge this to master. Thanks! |
Closed for now |
noloopclosure is a linter that disallow reference capture of loop variable inside of a closure.
https://github.com/fatanugraha/noloopclosure