Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoNewFuncRule = rule.Rule{ Name: "no-new-func", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { isGlobalFunction := func(id *ast.Node) bool { if utils.IsShadowed(id, "Function") { return false } if ctx.TypeChecker != nil { symbol := ctx.TypeChecker.GetSymbolAtLocation(id) if symbol == nil { return false } return !utils.IsSymbolDeclaredInFile(symbol, ctx.SourceFile) } return true } check := func(node *ast.Node) { var callee *ast.Node if node.Kind == ast.KindNewExpression { callee = node.AsNewExpression().Expression } else { callee = node.AsCallExpression().Expression } if callee == nil { return } unwrapped := ast.SkipOuterExpressions(callee, skipTransparent) if unwrapped.Kind == ast.KindIdentifier && unwrapped.AsIdentifier().Text == "Function" { if !isGlobalFunction(unwrapped) { return } ctx.ReportNode(node, msg) return } if node.Kind != ast.KindCallExpression { return } propName, ok := utils.AccessExpressionStaticName(unwrapped) if !ok || !callMethods[propName] { return } obj := ast.SkipOuterExpressions(utils.AccessExpressionObject(unwrapped), skipTransparent) if obj == nil || obj.Kind != ast.KindIdentifier || obj.AsIdentifier().Text != "Function" { return } if !isGlobalFunction(obj) { return } ctx.ReportNode(node, msg) } return rule.RuleListeners{ ast.KindNewExpression: check, ast.KindCallExpression: check, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.