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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ForbidComponentPropsRule = rule.Rule{
	Name: "react/forbid-component-props",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		cfg := parseOptions(options)
		return rule.RuleListeners{
			ast.KindJsxAttribute: func(node *ast.Node) {
				parent := reactutil.GetJsxParentElement(node)
				if parent == nil {
					return
				}
				tagName := reactutil.GetJsxTagName(parent)
				if tagName == nil {
					return
				}
				shape, ok := getTagShape(tagName)
				if !ok {
					return
				}
				if !shape.skipDomCheck && reactutil.IsCasedLowercaseFirstLetter(shape.componentName) {
					return
				}
				prop := reactutil.GetJsxPropName(node)
				if prop == "" {
					return
				}
				forbidden, opts := cfg.isForbidden(prop, shape.tag)
				if !forbidden {
					return
				}
				if opts != nil && opts.message != "" {
					ctx.ReportNode(node, rule.RuleMessage{
						Description: opts.message,
					})
					return
				}
				ctx.ReportNode(node, rule.RuleMessage{
					Id:          "propIsForbidden",
					Description: strings.ReplaceAll(msgPropIsForbidden, "{{prop}}", prop),
					Data:        map[string]string{"prop": prop},
				})
			},
		}
	},
}

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