Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultCaseRule = rule.Rule{ Name: "default-case", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { opts := parseOptions(options) return rule.RuleListeners{ ast.KindSwitchStatement: func(node *ast.Node) { switchStmt := node.AsSwitchStatement() if switchStmt == nil { return } caseBlock := switchStmt.CaseBlock if caseBlock == nil { return } clauses := caseBlock.AsCaseBlock() if clauses == nil || clauses.Clauses == nil { return } if len(clauses.Clauses.Nodes) == 0 { return } for _, clause := range clauses.Clauses.Nodes { if clause.Kind == ast.KindDefaultClause { return } } lastClause := clauses.Clauses.Nodes[len(clauses.Clauses.Nodes)-1] lastClauseEnd := lastClause.End() switchEnd := node.End() var lastComment *ast.CommentRange commentRange := utils.GetCommentsInRange(ctx.SourceFile, core.NewTextRange(lastClauseEnd, switchEnd)) for comment := range commentRange { c := comment lastComment = &c } if lastComment != nil { commentText := strings.TrimSpace(ctx.SourceFile.Text()[lastComment.Pos():lastComment.End()]) if strings.HasPrefix(commentText, "//") { commentText = strings.TrimSpace(commentText[2:]) } else if strings.HasPrefix(commentText, "/*") && strings.HasSuffix(commentText, "*/") { commentText = strings.TrimSpace(commentText[2 : len(commentText)-2]) } if opts.commentPattern.MatchString(commentText) { return } } ctx.ReportNode(node, rule.RuleMessage{ Id: "missingDefaultCase", Description: "Expected a default case.", }) }, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.