golangci / golangci-lint Public
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
Add nonamedreturns linter #2701
Conversation
Hey, thank you for opening your first Pull Request ! |
Hello, Requirements:
Recommended:
The golangci-lint team will edit this comment to check the boxes before and during the review. |
The license is still invalid https://github.com/FireFart/namedreturnlint/blob/aaa436feb6710f65388a6c3e5d7a185efedb119b/LICENSE#L655 And some other points need to be fixed. |
This text in the license file is not meant to be changed (take a look at your license for example) Everything else is addressed except |
yes, I read the license a bit too quickly.
You have to add an std lib import it's a requirement, it's a bit complex to explain in detail but this is required to be sure that the linter works well in several situations. The other points (except those for the team) still need to be fixed. |
ok thanks I hope everything is now addressed correctly |
This was the first time I tested this checklist, so it's not perfect. |
@firefart interesting linter I hope u know that you cannot do without named values when changing results via Moreover, nothing prevents you from using both a named results value and a no-nacked return. And in some cases using named results is useful: func GetList(ctx context.Context) (page []feed.Object, higher, lower *Cursor, err error) { /* ... */ }
func (c *cache) Get(userID string) (u *User, missed bool, err error) {
// ...
return nil, false, fmt.Errorf("save user in cache: %w", err)
// ...
}
It seems to me that we need to come up with a number of checks from the linter more complex than the binary logic "used / don't". Also the name of the linter is confusing now. |
FWIW I would consider usung this linter as is. I’ve worked at companies that did not allow named returnes (unconditionally like this linter) so we basically never changed returnes values in We don’t have a hard rule for that where I’m at now but I know some people (like me) think omitting variables at return or overwriting what gets returned makes the code harder to understand and it’s pretty unusual that we do that. Like you said though @Antonboom you can name them and still return named variables. A check for empty returns instead of checking the signature would be nice but I still think there’s a use-case for the linter and I’m not sure we should start deciding what linters to accept based on how many will find it useful. We already have a bunch of linters used by very few people that’s opinionated. Maybe something to discuss outside this PR? |
I have nothing against the linter, because previously received your support for my linters (dubious for other people). |
Hi, |
I agree with this point, maybe a better name can be The name Personally, I am also a "no named returns" guy (at least by default), because the readability is bad in the majority of the cases and they are sources of bugs. |
I've opened #2526 a couple of months ago which offers the same (and more) functionality but was closed immediately. Can it be reconsidered? |
The problem with your linter was that half of the linter was already provided by another linter. Note: I have not checked "the linter should not be a duplicate of another linter" and it's not a mistake. |
Jeah I agree I renamed the linter to reflect the purpose more cleanly |
Jeah I really like a strict rulebook to check against Some feedback: |
This comment was marked as off-topic.
This comment was marked as off-topic.
@firefart thanks for providing such a linter! Please make it pass the additional test cases described in https://github.com/leonklingele/funcresult/blob/9bcd76fcada71b380ab86f0f8b5ac8bb56ecee5c/pkg/analyzer/testdata/namedresult/src/named-require-unnamed/testcast.go |
@leonklingele thanks for the testcases! I missed a few in my implementation and updated the linter to match those too |
@ldez thanks! |
This has resulted in being unable to build golangci-lint without using the official module proxy, since the upstream checksum of |
This adds a new linter
nonamedreturns
https://github.com/FireFart/nonamedreturns
This linter simply checks for the use of named returns