Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoExtendNativeRule = rule.Rule{ Name: "no-extend-native", Run: func(ctx rule.RuleContext, opts any) rule.RuleListeners { o := parseOptions(opts) return rule.RuleListeners{ ast.KindIdentifier: func(node *ast.Node) { name := node.Text() if !nativeBuiltins[name] || o.exceptions[name] { return } identExpr := skipParensUp(node) parent := identExpr.Parent if parent == nil { return } obj := memberObject(parent) if obj != identExpr { return } propName, ok := staticMemberName(parent) if !ok || propName != "prototype" { return } if utils.IsShadowed(node, name) { return } prototypeAccess := skipParensUp(parent) next := prototypeAccess.Parent if next == nil { return } if memberObject(next) == prototypeAccess { memberAccess := skipParensUp(next) assign := memberAccess.Parent if assign != nil && assign.Kind == ast.KindBinaryExpression { bin := assign.AsBinaryExpression() if bin.OperatorToken != nil && isAssignmentOperator(bin.OperatorToken.Kind) && bin.Left == memberAccess { ctx.ReportNode(assign, rule.RuleMessage{ Id: "unexpected", Description: name + " prototype is read only, properties should not be added.", }) return } } } if next.Kind == ast.KindCallExpression { call := next.AsCallExpression() if call.Arguments == nil || len(call.Arguments.Nodes) == 0 || call.Arguments.Nodes[0] != prototypeAccess { return } if utils.IsSpecificMemberAccess(call.Expression, "Object", "defineProperty") || utils.IsSpecificMemberAccess(call.Expression, "Object", "defineProperties") { ctx.ReportNode(next, rule.RuleMessage{ Id: "unexpected", Description: name + " prototype is read only, properties should not be added.", }) } } }, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.