prefer_arrow_callback

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: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PreferArrowCallbackRule = rule.Rule{
	Name: "prefer-arrow-callback",
	Run: func(ctx rule.RuleContext, _raw []any) rule.RuleListeners {
		raw := rule.LegacyUnwrapOptions(_raw)
		opts := parseOptions(raw)
		return rule.RuleListeners{
			ast.KindFunctionExpression: func(node *ast.Node) {
				if opts.allowNamedFunctions {
					if name := node.Name(); name != nil && name.Kind == ast.KindIdentifier && name.Text() != "" {
						return
					}
				}
				if ast.GetFunctionFlags(node)&ast.FunctionFlagsGenerator != 0 {
					return
				}
				if functionNameReferenced(ctx, node) || hasArgumentsReference(ctx, node) {
					return
				}

				scope := getFunctionScopeInfo(node)
				info := getCallbackInfo(node)
				if !info.isCallback {
					return
				}
				if (opts.allowUnboundThis && scope.this && !info.isLexicalThis) || scope.super || scope.meta {
					return
				}

				msg := preferArrowCallbackMessage()
				if fixes := buildFixes(ctx, node, scope, info); len(fixes) > 0 {
					ctx.ReportNodeWithFixes(node, msg, fixes...)
				} else {
					ctx.ReportNode(node, msg)
				}
			},
		}
	},
}

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