Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ForbidDomPropsRule = rule.Rule{ Name: "react/forbid-dom-props", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { cfg := parseOptions(options) if len(cfg.byProp) == 0 { return rule.RuleListeners{} } 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 } if tagName.Kind != ast.KindIdentifier { return } tag := tagName.AsIdentifier().Text if !reactutil.IsCasedLowercaseFirstLetter(tag) { return } nameNode := node.AsJsxAttribute().Name() if nameNode == nil || nameNode.Kind != ast.KindIdentifier { return } prop := nameNode.AsIdentifier().Text if prop == "" { return } attr := node.AsJsxAttribute() if attr.Initializer == nil { return } propValue, hasValue := stringLiteralValue(node) forbidden, e := cfg.isForbidden(prop, tag, propValue, hasValue) if !forbidden { return } if e.message != "" { ctx.ReportNode(node, rule.RuleMessage{ Description: e.message, Data: map[string]string{"prop": prop, "propValue": propValue}, }) return } if e.hasDisallowedValues { desc := strings.ReplaceAll(msgPropIsForbiddenWithValue, "{{prop}}", prop) desc = strings.ReplaceAll(desc, "{{propValue}}", propValue) ctx.ReportNode(node, rule.RuleMessage{ Id: "propIsForbiddenWithValue", Description: desc, Data: map[string]string{"prop": prop, "propValue": propValue}, }) return } ctx.ReportNode(node, rule.RuleMessage{ Id: "propIsForbidden", Description: strings.ReplaceAll(msgPropIsForbidden, "{{prop}}", prop), Data: map[string]string{"prop": prop, "propValue": propValue}, }) }, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.