-
-
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
feat: add explicitreturn
linter
#3049
Conversation
Hey, thank you for opening your first Pull Request ! |
|
In order for a pull request adding a linter to be reviewed, the linter and the PR must follow some requirements. Pull Request Description
Linter
The Linter Tests Inside Golangci-lint
|
@maxsond Why the linter doesn't report about the first return? func MultipleReturnPaths() (x int, y string) {
if true {
return // ok ?
}
return // want `implicit return found in function MultipleReturnPaths`
} |
This is a bug. The current implementation only looks at statements directly inside the function statement, not at statements inside other statements (in this case an if statement). Will fix this. Thanks for catching it. |
Feel like a duplicate of nonamedreturns 🤔 |
It was born out of That's why I say it's closest to |
@maxsond you have to sign the CLA. |
@maxsond Please note that alexkohler/nakedret#18 has now been closed as "as designed". (It was just some confusion due to a misunderstanding.) |
Ah, cool. Then I think this linter is redundant. I'll go ahead and close it. |
Source: https://tildegit.org/indigo/explicitreturn
This adds a linter that requires functions to have explicit return statements. It's broadly similar to
nakedret
, but with a slightly different philosophy.For one thing, the size of the code doesn't matter. This will catch inline functions which I missed when I used
nakedret
(e.g.var x
in my test).As well, I would not consider alexkohler/nakedret#18 to be a bug because the function in that issue returns an error and a nil error is still a nil value so I would want to see that stated explicitly. The author of
nakedret
doesn't seem to take that view which is fine, but was part of what pushed me to writing this separately rather than working directly onnakedret
as well as a PR that's been open for review on that project for quite a while now.