Skip to content

nakedret doesn't check "return"s in conditionals #1317

@aaron42net

Description

@aaron42net

The nakedret linter embedded in golangci-lint appears to only check for "return" statements at the top level of the function, outside of conditionals. My expectation is that all returns are checked in functions above the specified length, regardless of nesting.

In golangci-lint's test suite, should line 6 of test/testdata/nakedret.go have an "// ERROR" marker? Letting the first "return" pass here seems wrong:

func NakedretIssue() (a int, b string) {
	if a > 0 {
		return
	}

	if b == "" {
		return 0, "0"
	}
[...]
	return // ERROR "naked return in func `NakedretIssue` with 31 lines of code"
}

Thanks!
-- Aaron

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependenciesRelates to an upstream dependencystaleNo recent correspondence or work activity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions