Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoAsyncPromiseExecutorRule = rule.CreateRule(rule.Rule{ Name: "no-async-promise-executor", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { return rule.RuleListeners{ ast.KindNewExpression: func(node *ast.Node) { if node == nil { return } expr := node.Expression() if expr == nil || expr.Kind != ast.KindIdentifier { return } if expr.Text() != "Promise" { return } args := node.Arguments() if len(args) == 0 { return } executor := args[0] if executor == nil { return } actualExecutor := executor for actualExecutor != nil && actualExecutor.Kind == ast.KindParenthesizedExpression { actualExecutor = actualExecutor.Expression() } if actualExecutor == nil { return } // Check if the executor is an async function var isAsync bool var asyncKeywordNode *ast.Node switch actualExecutor.Kind { case ast.KindFunctionExpression: mods := actualExecutor.Modifiers() if mods != nil { for _, mod := range mods.Nodes { if mod != nil && mod.Kind == ast.KindAsyncKeyword { isAsync = true asyncKeywordNode = mod break } } } case ast.KindArrowFunction: mods := actualExecutor.Modifiers() if mods != nil { for _, mod := range mods.Nodes { if mod != nil && mod.Kind == ast.KindAsyncKeyword { isAsync = true asyncKeywordNode = mod break } } } } if isAsync && asyncKeywordNode != nil { ctx.ReportNode(asyncKeywordNode, buildAsyncMessage()) } }, } }, })
NoAsyncPromiseExecutorRule disallows using an async function as a Promise executor
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.