-
Notifications
You must be signed in to change notification settings - Fork 2
Removing nakedret golint check #14
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
Conversation
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 don't have a strong opinion on this. But it looks good, otherwise. |
Can we revert this? Naked returns are almost always the wrong thing to do. Lots of reading on why to avoid them: https://levelup.gitconnected.com/go-naked-returns-4e2094b598e6 Since the cases for naked returns are so few, it's best to keep the check and let people explicitly disable it for lines of code they want to. https://golangci-lint.run/usage/false-positives/ |
@cep21 I took a look at the links you shared. There are great points in there. There is also an open PR where someone is advocating for the removal of Naked Returns, but it has not been accepted, and I don't think it will be 🤔 golang/go#21291 I hope it is okay that at this point I don't agree that they should be completely dropped, especially given they're used in core libraries themselves. They do have their place, and I don't think they should be gated behind a The The arguments against naked returns and named returned values mention shadowing. I think that is a problem easily solved by always running Part of the reason I'm drawn to naked returns is because I don't see value in functions that return the same variables list those same variables multiple times. I think it clutters the code with extra redundant text. Of course if there are varied returns in a function, then I agree mixing naked returns with non-naked returns is problematic and harms readability in that case. I was curious so I checked the main Go repository and there are quite a few naked returns:
Maybe we can revisit this again in the future? It seems like we both have strong opinions on it, but hoping in the meantime we can default to allowing by default since it is part of the language intentionally and also used in the core code. Thanks Jack. (Not the hill I want to die on, but those are my thoughts ❤️) |
Wouldn't make sense to remove backwards compatibility with existing code, so I agree the feature is here to stay.
Good advice there too.
And complexity and obfuscation
I don't believe you :)
That number seems suspect. Did you inspect those? Here is the first page.
That's the spec. Here are the first go files
Here's the first of those files
Seems you're counting returns without parameters. Can you link me to a few naked and named returns in go or kubernetes?
Gating makes sense when it's rare. |
I mentioned this in #12 but figured I'd just make a PR.
Naked returns with named variables are valid and useful, and can lend to much cleaner code when used correctly. I don't think we should block this feature of the language with a CI check ❤️.