jsx_max_depth

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JsxMaxDepthRule = rule.Rule{
	Name: "react/jsx-max-depth",
	Run: func(ctx rule.RuleContext, rawOptions any) rule.RuleListeners {
		opts := parseOptions(rawOptions)

		handleJSX := func(node *ast.Node) {

			if !isLeaf(node) {
				return
			}
			d := getDepth(node)
			if d > opts.max {
				report(ctx, node, d, opts.max)
			}
		}

		return rule.RuleListeners{
			ast.KindJsxElement:            handleJSX,
			ast.KindJsxSelfClosingElement: handleJSX,
			ast.KindJsxFragment:           handleJSX,
			ast.KindJsxExpression: func(node *ast.Node) {

				expr := jsxExpressionInner(node)
				if expr == nil {
					return
				}
				expr = ast.SkipParentheses(expr)
				if expr == nil || expr.Kind != ast.KindIdentifier {
					return
				}
				element := findJsxElementOrFragment(expr, ctx.TypeChecker, map[string]bool{}, 0)
				if element == nil {
					return
				}
				baseDepth := getDepth(node)
				checkDescendant(ctx, baseDepth, opts.max, reactutil.GetJsxChildren(element))
			},
		}
	},
}

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