jsx_props_no_spread_multi

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JsxPropsNoSpreadMultiRule = rule.Rule{
	Name: "react/jsx-props-no-spread-multi",
	Run: func(ctx rule.RuleContext, options []any) rule.RuleListeners {
		check := func(node *ast.Node) {
			attrs := reactutil.GetJsxElementAttributes(node)
			if len(attrs) == 0 {
				return
			}

			seen := map[string]struct{}{}
			for _, attr := range attrs {
				if !ast.IsJsxSpreadAttribute(attr) {
					continue
				}
				expr := attr.AsJsxSpreadAttribute().Expression

				if expr != nil {
					expr = ast.SkipParentheses(expr)
				}
				if !ast.IsIdentifier(expr) {
					continue
				}
				name := expr.AsIdentifier().Text
				if _, ok := seen[name]; ok {
					ctx.ReportNode(attr, rule.RuleMessage{
						Id:          "noMultiSpreading",
						Description: "Spreading the same expression multiple times is forbidden",
					})
				}
				seen[name] = struct{}{}
			}
		}

		return rule.RuleListeners{
			ast.KindJsxOpeningElement:     check,
			ast.KindJsxSelfClosingElement: check,
		}
	},
}

JsxPropsNoSpreadMultiRule disallows spreading the same identifier multiple times in one JSX opening 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