jsx_no_duplicate_props

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JsxNoDuplicatePropsRule = rule.Rule{
	Name: "react/jsx-no-duplicate-props",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		ignoreCase := false
		if optsMap := utils.GetOptionsMap(options); optsMap != nil {
			if v, ok := optsMap["ignoreCase"].(bool); ok {
				ignoreCase = v
			}
		}

		check := func(node *ast.Node) {
			attrs := reactutil.GetJsxElementAttributes(node)
			if len(attrs) == 0 {
				return
			}

			seen := map[string]struct{}{}
			for _, attr := range attrs {

				if !ast.IsJsxAttribute(attr) {
					continue
				}
				nameNode := attr.AsJsxAttribute().Name()
				if nameNode == nil {
					continue
				}

				if nameNode.Kind != ast.KindIdentifier {
					continue
				}
				name := nameNode.AsIdentifier().Text
				if ignoreCase {
					name = strings.ToLower(name)
				}
				if _, dup := seen[name]; dup {
					ctx.ReportNode(attr, rule.RuleMessage{
						Id:          "noDuplicateProps",
						Description: "No duplicate props allowed",
					})
					continue
				}
				seen[name] = struct{}{}
			}
		}

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

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