Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoDupeKeysRule = rule.Rule{ Name: "no-dupe-keys", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { return rule.RuleListeners{ ast.KindObjectLiteralExpression: func(node *ast.Node) { objLit := node.AsObjectLiteralExpression() if objLit == nil || objLit.Properties == nil { return } type propInfo struct { get bool set bool init bool } properties := make(map[string]*propInfo) for _, prop := range objLit.Properties.Nodes { if prop.Kind == ast.KindSpreadAssignment { continue } nameNode := prop.Name() if nameNode == nil { continue } name, isStatic := utils.GetStaticPropertyName(nameNode) if !isStatic { continue } if name == "__proto__" && prop.Kind == ast.KindPropertyAssignment && nameNode.Kind != ast.KindComputedPropertyName { continue } info, exists := properties[name] if !exists { info = &propInfo{} properties[name] = info } switch prop.Kind { case ast.KindGetAccessor: if info.get || info.init { ctx.ReportNode(prop, rule.RuleMessage{ Id: "unexpected", Description: fmt.Sprintf("Duplicate key '%s'.", name), }) } info.get = true case ast.KindSetAccessor: if info.set || info.init { ctx.ReportNode(prop, rule.RuleMessage{ Id: "unexpected", Description: fmt.Sprintf("Duplicate key '%s'.", name), }) } info.set = true default: if info.init || info.get || info.set { ctx.ReportNode(prop, rule.RuleMessage{ Id: "unexpected", Description: fmt.Sprintf("Duplicate key '%s'.", name), }) } info.init = true } } }, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.