no_self_compare

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 NoSelfCompareRule = rule.Rule{
	Name: "no-self-compare",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		return rule.RuleListeners{
			ast.KindBinaryExpression: func(node *ast.Node) {
				bin := node.AsBinaryExpression()
				if bin == nil || bin.OperatorToken == nil {
					return
				}
				switch bin.OperatorToken.Kind {
				case ast.KindEqualsEqualsEqualsToken,
					ast.KindEqualsEqualsToken,
					ast.KindExclamationEqualsEqualsToken,
					ast.KindExclamationEqualsToken,
					ast.KindGreaterThanToken,
					ast.KindLessThanToken,
					ast.KindGreaterThanEqualsToken,
					ast.KindLessThanEqualsToken:
				default:
					return
				}
				if utils.HasSameTokens(ctx.SourceFile, bin.Left, bin.Right) {
					ctx.ReportNode(node, rule.RuleMessage{
						Id:          "comparingToSelf",
						Description: "Comparing to itself is potentially pointless.",
					})
				}
			},
		}
	},
}

https://eslint.org/docs/latest/rules/no-self-compare

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