no_empty

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2026 License: MIT, MIT Imports: 4 Imported by: 0

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.",
					})
				}
			},
		}
	},
}

https://eslint.org/docs/latest/rules/no-empty

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL