Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var MaxNestedCallbacksRule = rule.Rule{ Name: "max-nested-callbacks", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { threshold := parseThreshold(options) // `callbackStack` mirrors ESLint's stack of FunctionExpression / // ArrowFunctionExpression nodes that sit *directly* under a // CallExpression — i.e. function-likes used as call arguments or as // the callee of an immediately-invoked call. Push happens only when // the (paren-flattened) parent is a CallExpression; pop fires on // every function-like exit, even when the entry didn't push. The // asymmetry is preserved verbatim from ESLint to keep diagnostic // counts byte-for-byte identical with upstream. var callbackStack []*ast.Node check := func(node *ast.Node) { parent := ast.WalkUpParenthesizedExpressions(node.Parent) if parent != nil && ast.IsCallExpression(parent) { callbackStack = append(callbackStack, node) } if len(callbackStack) > threshold { ctx.ReportNode(node, buildExceedMessage(len(callbackStack), threshold)) } } pop := func(node *ast.Node) { if len(callbackStack) > 0 { callbackStack = callbackStack[:len(callbackStack)-1] } } return rule.RuleListeners{ ast.KindFunctionExpression: check, rule.ListenerOnExit(ast.KindFunctionExpression): pop, ast.KindArrowFunction: check, rule.ListenerOnExit(ast.KindArrowFunction): pop, ast.KindMethodDeclaration: check, rule.ListenerOnExit(ast.KindMethodDeclaration): pop, ast.KindGetAccessor: check, rule.ListenerOnExit(ast.KindGetAccessor): pop, ast.KindSetAccessor: check, rule.ListenerOnExit(ast.KindSetAccessor): pop, ast.KindConstructor: check, rule.ListenerOnExit(ast.KindConstructor): pop, } }, }
MaxNestedCallbacksRule enforces a maximum depth of nested callbacks. https://eslint.org/docs/latest/rules/max-nested-callbacks
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.