no_return_assign

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: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoReturnAssignRule = rule.Rule{
	Name: "no-return-assign",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		always := parseMode(options) == "always"

		return rule.RuleListeners{
			ast.KindBinaryExpression: func(node *ast.Node) {
				if !ast.IsAssignmentExpression(node, false) {
					return
				}

				if !always && node.Parent != nil && ast.IsParenthesizedExpression(node.Parent) {
					return
				}

				currentChild := node
				parent := node.Parent
				for parent != nil && !isSentinel(parent) {
					currentChild = parent
					parent = parent.Parent
				}
				if parent == nil {
					return
				}
				switch {
				case ast.IsReturnStatement(parent):
					ctx.ReportNode(parent, rule.RuleMessage{
						Id:          "returnAssignment",
						Description: "Return statement should not contain assignment.",
					})
				case ast.IsArrowFunction(parent):
					if arrow := parent.AsArrowFunction(); arrow != nil && arrow.Body == currentChild {
						ctx.ReportNode(parent, rule.RuleMessage{
							Id:          "arrowAssignment",
							Description: "Arrow function should not return assignment.",
						})
					}
				}
			},
		}
	},
}

https://eslint.org/docs/latest/rules/no-return-assign

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