no_danger

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoDangerRule = rule.Rule{
	Name: "react/no-danger",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		var customComponentNames []string
		if optsMap := utils.GetOptionsMap(options); optsMap != nil {
			if arr, ok := optsMap["customComponentNames"].([]interface{}); ok {
				for _, item := range arr {
					if name, ok := item.(string); ok {
						customComponentNames = append(customComponentNames, name)
					}
				}
			}
		}

		return rule.RuleListeners{
			ast.KindJsxAttribute: func(node *ast.Node) {
				attrName := reactutil.GetJsxPropName(node)
				if !dangerousProps[attrName] {
					return
				}

				parent := reactutil.GetJsxParentElement(node)
				if parent == nil {
					return
				}

				matched := reactutil.IsDOMComponent(parent)
				if !matched && len(customComponentNames) > 0 {
					functionName := getTagNameText(ctx.SourceFile, reactutil.GetJsxTagName(parent))
					for _, pattern := range customComponentNames {

						if ok, err := path.Match(pattern, functionName); ok && err == nil {
							matched = true
							break
						}
					}
				}
				if !matched {
					return
				}

				ctx.ReportNode(node, rule.RuleMessage{
					Id:          "dangerousProp",
					Description: "Dangerous property '" + attrName + "' found",
				})
			},
		}
	},
}

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