Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ConstructorSuperRule = rule.CreateRule(rule.Rule{ Name: "constructor-super", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { return rule.RuleListeners{ ast.KindConstructor: func(node *ast.Node) { if !isConstructor(node) { return } classNode := getClassNode(node) if classNode == nil { return } hasExtends := hasValidExtends(classNode) body := node.Body() analysis := analyzeSuperCallsInBody(body) if hasExtends { if !analysis.hasSuperCall { if allPathsTerminateEarly(body) { } else if hasBranchingWithEarlyReturn(body) { ctx.ReportNode(node, buildMissingSome()) } else { ctx.ReportNode(node, buildMissingAll()) } } else if !analysis.allPathsHaveSuper { ctx.ReportNode(node, buildMissingSome()) } else if analysis.allPathsHaveSuper && len(analysis.superCallLocations) > 1 { duplicates := findDuplicateSuperCalls(body, analysis.superCallLocations) for _, superCall := range duplicates { superKeyword := superCall.Expression() if superKeyword != nil && superKeyword.Kind == ast.KindSuperKeyword { ctx.ReportNode(superKeyword, buildDuplicate()) } else { ctx.ReportNode(superCall, buildDuplicate()) } } } } else { if analysis.hasSuperCall { for _, superCall := range analysis.superCallLocations { superKeyword := superCall.Expression() if superKeyword != nil && superKeyword.Kind == ast.KindSuperKeyword { ctx.ReportNode(superKeyword, buildBadSuper()) } else { ctx.ReportNode(superCall, buildBadSuper()) } } } } }, } }, })
ConstructorSuperRule enforces proper super() calls in constructors
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.