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
ITP: linter to enforce named / unnamed result parameters [intent-to-provide] #1201
Comments
I'm not sure either of these options can be followed consistently across a real codebase. Suppose that you want to avoid the named results at all costs. Then you'll have a problem when you want to override the return value from the deferred call. It's useful in combination with Using the named results all the time looks just too weird. In my experience, people tend to use them only in a few situations. The one is already mentioned above and another one is when your return values are not self-explanatory. There is also an unnamedResult checker that does a somewhat similar check. While it may have some merit when you want to catch accidental named params, I don't think that unconditional lint is a way to go. A new checker that reports unnecessary named parameters could be useful. |
For me personally, the linter is useful to prevent accidentally-named-result-params. When named result params are needed from time to time, there's always the option to whitelist them with a |
Don't get me wrong, I'm not saying that this idea shouldn't exist. We have an extension point via https://github.com/quasilyte/go-ruleguard to allow such very opinionated, team-specific checks. It's possible to express funcresult linter in most cases, but it'll be a little bit awkward. |
Part of golangci/golangci-lint#2701. |
I maintain a linter which enforces the use of named / unnamed result parameters: https://github.com/leonklingele/funcresult
Unfortunately, it did not find its way to golangci-lint — was rejected: golangci/golangci-lint#2526 (comment)
Would you be willing to accept a linter which provides such functionality?
The text was updated successfully, but these errors were encountered: