no_compare_neg_zero

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoCompareNegZeroRule = rule.CreateRule(rule.Rule{
	Name: "no-compare-neg-zero",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {

		operatorsToCheck := map[ast.Kind]bool{
			ast.KindGreaterThanToken:             true,
			ast.KindGreaterThanEqualsToken:       true,
			ast.KindLessThanToken:                true,
			ast.KindLessThanEqualsToken:          true,
			ast.KindEqualsEqualsToken:            true,
			ast.KindEqualsEqualsEqualsToken:      true,
			ast.KindExclamationEqualsToken:       true,
			ast.KindExclamationEqualsEqualsToken: true,
		}

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

				if !operatorsToCheck[binary.OperatorToken.Kind] {
					return
				}

				if isNegativeZero(binary.Left) || isNegativeZero(binary.Right) {

					operatorText := getOperatorText(binary.OperatorToken.Kind)
					ctx.ReportNode(node, buildCompareNegZeroMessage(operatorText))
				}
			},
		}
	},
})

NoCompareNegZeroRule disallows comparisons to negative zero

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