nakedret icon indicating copy to clipboard operation
nakedret copied to clipboard

Why this reports error for named return

Open lance6716 opened this issue 3 years ago • 2 comments

noticed https://github.com/alexkohler/nakedret/blob/b2c01465241327a7db35ec77f94ff19168bcabaa/testdata/nested.go#L11-L17

I think this return in line 16 is not harmful, and this linter should not report error :thinking:

lance6716 avatar Jan 18 '22 09:01 lance6716

Hey there - it looks like this is a bug - thanks for the report! I like won't have the time to get to this in the immediate future, but if anyone is looking for an easy bug to fix, I imagine this wouldn't be too bad to handle.

alexkohler avatar Jan 18 '22 14:01 alexkohler

@lance6716 @alexkohler Why do you believe this to be a bug?

rittneje avatar Aug 08 '22 20:08 rittneje

@lance6716 @alexkohler Why do you believe this to be a bug?

This is not that severe as a bug IMO. As the README says

Naked returns are okay if the function is a handful of lines. Once it's a medium sized function, be explicit with your return values.

Maybe different guys have different threshold about what's "a handful of lines"

lance6716 avatar Aug 09 '22 02:08 lance6716

@rittneje heh, on a second look, you're right. I originally read this bug as a naked return being reported on line 14, not 16. Line 16 reporting a naked return is as designed 👍

alexkohler avatar Aug 09 '22 02:08 alexkohler

Maybe different guys have different threshold about what's "a handful of lines"

That is fair - that threshold should be configurable through the -l parameter.

alexkohler avatar Aug 09 '22 02:08 alexkohler