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

Update WSL to v1.2.5 #811

Merged
merged 4 commits into from Oct 14, 2019
Merged

Update WSL to v1.2.5 #811

merged 4 commits into from Oct 14, 2019

Conversation

bombsimon
Copy link
Member

  • Fix false positive multiline case (test added)
  • Fix false positive slice expression (test added)
  • Fix false positive index expression (test added)
  • Support to configure/allow cuddle declarations (example config added)
  • Support to configure/allow case blocks to end with whitespace (example config added)
  • Support cuddle defer http body close

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.

@bombsimon
Copy link
Member Author

Build for 1.13 OK but not for 1.12. Can reproduce with make test (or just the step go test). Seems to be something with TestConcurrentReadsAndWrites from internal/renameio, an intermittent error:

$ 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.

pkg/config/config.go Outdated Show resolved Hide resolved
* 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
@bombsimon bombsimon changed the title Update WSL to v1.2.4 Update WSL to v1.2.5 Oct 14, 2019
@bombsimon
Copy link
Member Author

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.

@bombsimon bombsimon requested a review from jirfag October 14, 2019 16:42
}

xxx := "xxx"
if _, ok := aMap[key]; ok { // ERROR "if statements should only be cuddled with assignments used in the if statement itself"
Copy link
Member

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

Copy link
Member Author

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
}

Copy link
Member Author

@bombsimon bombsimon Oct 14, 2019

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!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thank you!

@jirfag jirfag added the question Further information is requested label Oct 14, 2019
}

xxx := "xxx"
if _, ok := aMap[key]; ok { // ERROR "if statements should only be cuddled with assignments used in the if statement itself"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thank you!

@jirfag jirfag merged commit 22df2d7 into golangci:master Oct 14, 2019
@ldez ldez added linter: update version Update version of linter and removed question Further information is requested labels Dec 7, 2020
@ldez ldez added this to the v1.21 milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linter: update version Update version of linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants