Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoConstantBinaryExpressionRule = rule.CreateRule(rule.Rule{ Name: "no-constant-binary-expression", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { return rule.RuleListeners{ ast.KindBinaryExpression: func(node *ast.Node) { binary := node.AsBinaryExpression() if binary == nil || binary.OperatorToken == nil { return } operator := binary.OperatorToken.Kind switch operator { case ast.KindAmpersandAmpersandToken: if isConstant(binary.Left) { ctx.ReportNode(node, buildConstantShortCircuitMessage("&&")) } case ast.KindBarBarToken: if isConstant(binary.Left) { ctx.ReportNode(node, buildConstantShortCircuitMessage("||")) } case ast.KindQuestionQuestionToken: if hasConstantNullishness(binary.Left) { ctx.ReportNode(node, buildConstantShortCircuitMessage("??")) } } switch operator { case ast.KindEqualsEqualsToken, ast.KindExclamationEqualsToken, ast.KindEqualsEqualsEqualsToken, ast.KindExclamationEqualsEqualsToken: if isAlwaysNew(binary.Left) && isAlwaysNew(binary.Right) { ctx.ReportNode(node, buildBothAlwaysNewMessage()) return } if isAlwaysNew(binary.Left) && !isConstant(binary.Right) { ctx.ReportNode(node, buildAlwaysNewMessage()) return } if isAlwaysNew(binary.Right) && !isConstant(binary.Left) { ctx.ReportNode(node, buildAlwaysNewMessage()) return } constantOperand := findBinaryExpressionConstantOperand(binary.Left, binary.Right, operator) if constantOperand != nil { ctx.ReportNode(node, buildConstantBinaryOperandMessage()) } } }, } }, })
NoConstantBinaryExpressionRule detects constant binary expressions
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.