Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoEmptyRule = rule.Rule{ Name: "no-empty", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { opts := parseOptions(options) return rule.RuleListeners{ ast.KindBlock: func(node *ast.Node) { block := node.AsBlock() if block == nil { return } if block.Statements != nil && len(block.Statements.Nodes) > 0 { return } if isFunction(node.Parent) { return } if opts.allowEmptyCatch && node.Parent != nil && node.Parent.Kind == ast.KindCatchClause { return } if hasCommentInside(ctx.SourceFile.Text(), node.Pos(), node.End()) { return } ctx.ReportNode(node, rule.RuleMessage{ Id: "unexpected", Description: "Empty block statement.", }) }, ast.KindSwitchStatement: func(node *ast.Node) { switchStmt := node.AsSwitchStatement() if switchStmt == nil || switchStmt.CaseBlock == nil { return } caseBlock := switchStmt.CaseBlock.AsCaseBlock() if caseBlock == nil { return } if caseBlock.Clauses == nil || len(caseBlock.Clauses.Nodes) == 0 { if hasCommentInside(ctx.SourceFile.Text(), switchStmt.CaseBlock.Pos(), switchStmt.CaseBlock.End()) { return } ctx.ReportNode(node, rule.RuleMessage{ Id: "unexpected", Description: "Empty switch statement.", }) } }, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.