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 WSL to v1.2.5 #811
Update WSL to v1.2.5 #811
Conversation
Build for 1.13 OK but not for 1.12. Can reproduce with $ for _ in {1..5}; do go test ./internal/renameio/... -count=1; done
ok github.com/golangci/golangci-lint/internal/renameio 16.203s
ok github.com/golangci/golangci-lint/internal/renameio 15.782s
ok github.com/golangci/golangci-lint/internal/renameio 16.256s
--- FAIL: TestConcurrentReadsAndWrites (15.79s)
renameio_test.go:75: unexpected error: rename /var/folders/q3/bf76j42160j2nt4s2tz1_fd40000gn/T/renameio152466423/blob.bin614503871.tmp /var/folders/q3/bf76j42160j2nt4s2tz1_fd40000gn/T/renameio152466423/blob.bin: no such file or directory
renameio_test.go:127: 2047 (of 2048) writes succeeded; want ≥ 2048
renameio_test.go:142: 2048 (of 2048) reads succeeded (ok: ≥ 2048)
FAIL
FAIL github.com/golangci/golangci-lint/internal/renameio 15.964s
FAIL
ok github.com/golangci/golangci-lint/internal/renameio 16.014s I'll try to see i I can figure anything out if this isn't already a known issue. |
* Fix false positive multiline case * Fix false positive slice expression * Fix false positive index expression * Support to configure/allow cuddle declarations * Support to configurre/allow case blocks to end with whitespace * Support cuddle defer http body close
* Support output comments for example functions
I forgot that I tried the fix/commit button from GitHub after the requested change and had rebased on master locally to avoid conflicts. Did a force push (with lease) to get back to original state and had to re-do the commit for bad field tag. Since I had a PR with a bug merged I added a test and renamed this to v1.2.5. |
} | ||
|
||
xxx := "xxx" | ||
if _, ok := aMap[key]; ok { // ERROR "if statements should only be cuddled with assignments used in the if statement itself" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but how to rewrite this code properly? it's the common coding pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see how that's a question for the linter itself and there's an issue here to allow the variable to be cuddled if it's used anywhere in the block body. Before this PR the linter gave an error even if xxx
was used as the index expression. :(
The way to rewrite to satisfy the linter:
notUsedInIf := "separated from the statement"
if _, ok := aMap[key]; ok {
fmt.Println("Not used here either")
// Many lines later...
fmt.Println(notUsedInIf)
}
And if the variable is used it may be cuddled.
key := "used in if"
if _, ok := aMap[key]; ok {
fmt.Println("ok")
}
Or if it's used after the condition.
xxx := "not in if but first in block"
if _, ok := aMap[key]; ok {
fmt.Println(xxx) // Ok
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got a bit confused after writing my comment and had a revisit to Effective Go. I see that a lot of the code uses a pattern that WSL discourages in favour of readability. Although I don't see newlines being discussed in the documentation and the examples doesn't state it's the only (or preferred way) to handle empty lines.
The reason for me adding it to this project is that I got asked by two of the places I've worked who uses golangci-lint
and uses this kind of style to improve readability. I got a bit anxious about it since it's mainly based on personal preferences and sent and e-mail to you but I didn't get any response so I didn't revert anything.
I know it's not much but since this got merged in v1.20.0 the linter have had 10 stars and a few issues added so there seems to be a bit of an interest. Although maybe not enough to be a part of this project?
Do you think this kind of linter/styling is out of scope for golangci-lint? If so, do you wan't me to revert it being added?
If you wan't more details and thoughts behind this linter please give the README from the repository a few minutes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thank you!
} | ||
|
||
xxx := "xxx" | ||
if _, ok := aMap[key]; ok { // ERROR "if statements should only be cuddled with assignments used in the if statement itself" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thank you!
Note: Had to update the test runner with
--max-same-issues=10
to allow my tests to cover added false-positives which yields the same error.