no_setter_return

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoSetterReturnRule = rule.Rule{
	Name: "no-setter-return",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		return rule.RuleListeners{
			ast.KindReturnStatement: func(node *ast.Node) {
				ret := node.AsReturnStatement()
				if ret.Expression == nil {
					return
				}
				enclosing := findEnclosingFunction(node)
				if enclosing != nil && isSetterFunction(enclosing, ctx) {
					ctx.ReportNode(node, buildSetterMessage())
				}
			},
			ast.KindArrowFunction: func(node *ast.Node) {

				body := node.Body()
				if body == nil || body.Kind == ast.KindBlock {
					return
				}
				if isSetterFunction(node, ctx) {
					ctx.ReportNode(body, buildSetterMessage())
				}
			},
		}
	},
}

NoSetterReturnRule disallows returning a value from a setter. Setters cannot meaningfully return values; any return value is silently ignored. A bare `return;` (without a value) is allowed for control flow.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL