-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
update scopelint with looppointer or exportloopref #1041
Comments
Should we just add both |
I think so. Let the user choose what they want. And document it adequately mentioning which is to be used when. |
If you are going to include only one, please include |
Agreed with comment from @tamalsaha above, maybe exportloopref is good enough :) |
Since Case 1: pass the pointer to the function to export. Case 2: pass the pointer to the local variable, and export it. package main
type List []*int
func (l *List) AppendP(p *int) {
*l = append(*l, p)
}
func main() {
var slice []*int
list := List{}
println("loop expect exporting 10, 11, 12, 13")
for _, v := range []int{10, 11, 12, 13} {
list.AppendP(&v) // Case 1: wanted "exporting a pointer for the loop variable v", but cannot be found
p := &v // p is the local variable
slice = append(slice, p) // Case 2: wanted "exporting a pointer for the loop variable v", but cannot be found
}
println(`slice expecting "10, 11, 12, 13" but "13, 13, 13, 13"`)
for _, p := range slice {
printp(p)
}
println(`array expecting "10, 11, 12, 13" but "13, 13, 13, 13"`)
for _, p := range ([]*int)(list) {
printp(p)
}
}
func printp(p *int) {
println(*p)
} So we may use https://github.com/kyoh86/exportloopref#known-false-negatives |
Hi, I just changed the version of golangci-lint that I was using from v1.33.0 to v1.44.2. I am using go1.17.
With scopelint, I got:
With exportloopref, I got no issue. Not sure, which is the correct behavior for a linter? Is it not a linter issue now? |
@may98ank You can read comments above, README of exportloopref and README of looppointer to understand the difference. They have different policies. |
Does this have a use since recent loop changes in go 1.22? https://tip.golang.org/doc/go1.22#language
Unsure what needs to change if anything, as this would seem to avoid the root reason for loop ref issues. |
Hi there,
I am totally aware that the project is going through some rough times. So there's no pressure to work on this right now. Nevertheless, I wanted to file this to just to keep a record.
The author of scopelint has deprecated it for other better linters: https://github.com/kyoh86/scopelint#obsoleted.
Let's use either of them to remain up to date.
Thanks for all the work.
The text was updated successfully, but these errors were encountered: