Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoConstAssignRule = rule.CreateRule(rule.Rule{ Name: "no-const-assign", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { constSymbols := make(map[*ast.Symbol]bool) return rule.RuleListeners{ ast.KindVariableDeclarationList: func(node *ast.Node) { if !isConstBinding(node) { return } varDeclList := node.AsVariableDeclarationList() if varDeclList == nil || varDeclList.Declarations == nil { return } for _, decl := range varDeclList.Declarations.Nodes { if decl.Kind != ast.KindVariableDeclaration { continue } varDecl := decl.AsVariableDeclaration() if varDecl == nil || varDecl.Name() == nil { continue } collectSymbols(varDecl.Name(), &ctx, constSymbols) } }, ast.KindIdentifier: func(node *ast.Node) { checkIdentifierWrite(node, &ctx, constSymbols) }, ast.KindShorthandPropertyAssignment: func(node *ast.Node) { shorthand := node.AsShorthandPropertyAssignment() if shorthand == nil || shorthand.Name() == nil { return } if !isInDestructuringAssignment(node) { return } if ctx.TypeChecker == nil { return } symbol := ctx.TypeChecker.GetSymbolAtLocation(shorthand.Name()) if symbol == nil { return } if !constSymbols[symbol] { return } identName := getIdentifierName(shorthand.Name()) ctx.ReportNode(shorthand.Name(), buildConstMessage(identName)) }, } }, })
NoConstAssignRule disallows reassigning const variables
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.