no_empty_function

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT, MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoEmptyFunctionRule = rule.Rule{
	Name: "no-empty-function",
	Run: func(ctx rule.RuleContext, _options []any) rule.RuleListeners {
		options := rule.LegacyUnwrapOptions(_options)
		opts := parseOptions(options)

		check := func(node *ast.Node) {
			body := node.Body()
			if body == nil || body.Kind != ast.KindBlock {
				return
			}
			if len(body.Statements()) != 0 {
				return
			}
			if utils.HasCommentInsideNode(ctx.SourceFile, body) {
				return
			}
			if isAllowedEmptyFunction(node, opts) {
				return
			}

			name := emptyFunctionDisplayName(node)
			bodyRange := utils.TrimNodeTextRange(ctx.SourceFile, body)
			message := rule.RuleMessage{
				Id:          "unexpected",
				Description: fmt.Sprintf("Unexpected empty %s.", name),
				Data:        map[string]string{"name": name},
			}
			suggestionMessage := rule.RuleMessage{
				Id:          "suggestComment",
				Description: fmt.Sprintf("Add comment inside empty %s.", name),
				Data:        map[string]string{"name": name},
			}
			ctx.ReportRangeWithSuggestions(bodyRange, message, rule.RuleSuggestion{
				Message: suggestionMessage,
				FixesArr: []rule.RuleFix{
					rule.RuleFixReplaceRange(utils.BracedNodeInnerRange(ctx.SourceFile, body), " /* empty */ "),
				},
			})
		}

		return rule.RuleListeners{
			ast.KindArrowFunction:       check,
			ast.KindConstructor:         check,
			ast.KindFunctionDeclaration: check,
			ast.KindFunctionExpression:  check,
			ast.KindGetAccessor:         check,
			ast.KindMethodDeclaration:   check,
			ast.KindSetAccessor:         check,
		}
	},
}

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

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