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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoMultiAssignRule = rule.Rule{
	Name: "no-multi-assign",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		opts := parseOptions(options)

		return rule.RuleListeners{
			ast.KindBinaryExpression: func(node *ast.Node) {
				binExpr := node.AsBinaryExpression()
				if binExpr == nil || binExpr.OperatorToken == nil {
					return
				}
				if !ast.IsAssignmentOperator(binExpr.OperatorToken.Kind) {
					return
				}

				parent := ast.WalkUpParenthesizedExpressions(node.Parent)
				if parent == nil {
					return
				}

				switch parent.Kind {
				case ast.KindVariableDeclaration:
					decl := parent.AsVariableDeclaration()
					if decl != nil && decl.Initializer != nil &&
						ast.SkipParentheses(decl.Initializer) == node {
						ctx.ReportNode(node, buildMessage())
					}
				case ast.KindPropertyDeclaration:
					decl := parent.AsPropertyDeclaration()
					if decl != nil && decl.Initializer != nil &&
						ast.SkipParentheses(decl.Initializer) == node {
						ctx.ReportNode(node, buildMessage())
					}
				case ast.KindBinaryExpression:
					if opts.ignoreNonDeclaration {
						return
					}
					outer := parent.AsBinaryExpression()
					if outer == nil || outer.OperatorToken == nil {
						return
					}
					if !ast.IsAssignmentOperator(outer.OperatorToken.Kind) {
						return
					}
					if outer.Right != nil && ast.SkipParentheses(outer.Right) == node {
						ctx.ReportNode(node, buildMessage())
					}
				}
			},
		}
	},
}

https://eslint.org/docs/latest/rules/no-multi-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