How the tsgolint rule system works
mainRules in tsgolint are implemented using a visitor pattern. Instead of traversing the entire tree manually, each rule registers listeners for specific TypeScript AST (Abstract Syntax Tree) node types. When the linter encounters a registered node type, it executes the corresponding check function. Rules can also access the TypeScript checker to perform type-aware analysis.
func (r *Rule) Run(ctx RuleContext) RuleListeners {
return RuleListeners{
ast.FunctionDeclaration: r.checkFunction,
ast.CallExpression: r.checkCall,
}
}