linter for naked returns

259 views
Skip to first unread message

Dan Kortschak

unread,
Nov 16, 2015, 11:51:58 PM11/16/15
to golang-nuts
Is there a linter for naked return of named return variable? A quick
google did not find one for me.

Andrew Gerrand

unread,
Nov 17, 2015, 12:06:25 AM11/17/15
to Dan Kortschak, golang-nuts
What situations would you like such a tool to report on?

Dan Kortschak

unread,
Nov 17, 2015, 12:16:46 AM11/17/15
to Andrew Gerrand, golang-nuts
On Tue, 2015-11-17 at 16:05 +1100, Andrew Gerrand wrote:
> What situations would you like such a tool to report on?

Any case where a return parameter list includes named vars and the
return is naked:

func foo() (thing, to, pass int) {
// many calculations...
return
}


Markus Zimmermann

unread,
Nov 17, 2015, 5:52:51 AM11/17/15
to golang-nuts
I cannot think of one but that thing is written in just a few lines. The question is why do you want to avoid that?

Markus Zimmermann

unread,
Nov 17, 2015, 6:36:12 AM11/17/15
to golang-nuts

Dan Kortschak

unread,
Nov 17, 2015, 1:38:16 PM11/17/15
to Markus Zimmermann, golang-nuts
Thanks, Markus.

It's not a general thing I want to avoid, just in a package we are working on at the moment. Named return values are needed for documentation purposes and for clarity in the unfortunately huge functions (historical reasons) naked returns should be avoided.
Reply all
Reply to author
Forward
0 new messages