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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoSelfAssignRule = rule.Rule{
	Name: "no-self-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
				}

				op := binExpr.OperatorToken.Kind
				if op != ast.KindEqualsToken &&
					op != ast.KindAmpersandAmpersandEqualsToken &&
					op != ast.KindBarBarEqualsToken &&
					op != ast.KindQuestionQuestionEqualsToken {
					return
				}

				eachSelfAssignment(binExpr.Left, binExpr.Right, opts.props, func(rightNode *ast.Node) {
					name := getNodeText(ctx.SourceFile, rightNode)
					ctx.ReportNode(rightNode, rule.RuleMessage{
						Id:          "selfAssignment",
						Description: "'" + name + "' is assigned to itself.",
					})
				})
			},
		}
	},
}

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