Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoExtraBooleanCastRule = rule.Rule{ Name: "no-extra-boolean-cast", Run: func(ctx rule.RuleContext, ruleOptions any) rule.RuleListeners { opts := parseOptions(ruleOptions) negationMsg := rule.RuleMessage{ Id: "unexpectedNegation", Description: "Redundant double negation.", } callMsg := rule.RuleMessage{ Id: "unexpectedCall", Description: "Redundant Boolean call.", } return rule.RuleListeners{ ast.KindPrefixUnaryExpression: func(node *ast.Node) { prefix := node.AsPrefixUnaryExpression() if prefix == nil || prefix.Operator != ast.KindExclamationToken { return } operand := prefix.Operand if operand == nil || !ast.IsPrefixUnaryExpression(operand) { return } if operand.AsPrefixUnaryExpression().Operator != ast.KindExclamationToken { return } if !isInFlaggedContext(node, opts) { return } if fixes := buildNegationFix(ctx, node); fixes != nil { ctx.ReportNodeWithFixes(node, negationMsg, fixes...) } else { ctx.ReportNode(node, negationMsg) } }, ast.KindCallExpression: func(node *ast.Node) { if !isBooleanFunctionOrConstructorCall(node) { return } if !isInFlaggedContext(node, opts) { return } if fixes := buildCallFix(ctx, node); fixes != nil { ctx.ReportNodeWithFixes(node, callMsg, fixes...) } else { ctx.ReportNode(node, callMsg) } }, } }, }
NoExtraBooleanCastRule disallows unnecessary boolean casts. Reports `!!expr` (double negation) and `Boolean(expr)` calls in contexts that already coerce to boolean.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.