Skip to content

no-naked-return

Require explicit values when returning from named-result functions.

Updated View as Markdown

Default severity: warning

Reports a bare return when the nearest function declaration or function literal has at least one named result. Naked returns make data flow implicit: the reader must search backward to determine which values are returned.

Bad

func value() (result int) {
	result = calculate()
	return
}

Good

func value() (result int) {
	result = calculate()
	return result
}

The rule does not require removing named results. It only requires the return statement to name the values being returned.

Configuration

[checks.no-naked-return]
severity = "warning"
excludes = ["generated/**"]
Navigation

Type to search…

↑↓ navigate↵ selectEsc close