Documentation
¶
Overview ¶
Package helpers provides shared utilities for rule implementations.
Package helpers provides shared utilities for rule implementations.
Index ¶
- func AnalyzeFuncBodies(ctx *core.FileContext, checker FuncBodyChecker) []*core.Violation
- func AnalyzeFuncDecls(ctx *core.FileContext, checker FuncDeclChecker) []*core.Violation
- func AnalyzeGoAndFrontend(ctx *core.FileContext, analyzeGo func(*core.FileContext) []*core.Violation, ...) []*core.Violation
- func IsInComment(line, substr string) bool
- func IsInStringOrComment(line, substr string) bool
- func IsInsideBackticks(line, substr string) bool
- func IsInsideString(line, substr string) bool
- type FuncBodyChecker
- type FuncDeclChecker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnalyzeFuncBodies ¶
func AnalyzeFuncBodies(ctx *core.FileContext, checker FuncBodyChecker) []*core.Violation
AnalyzeFuncBodies is a helper for rules that analyze function bodies. It handles the common boilerplate of: - Checking if AST exists - Iterating over function declarations - Filtering out functions without bodies
Usage:
func (r *MyRule) AnalyzeFile(ctx *core.FileContext) []*core.Violation {
if !ctx.IsGoFile() || ctx.IsTestFile() {
return nil
}
return helpers.AnalyzeFuncBodies(ctx, r.checkFunction)
}
func AnalyzeFuncDecls ¶
func AnalyzeFuncDecls(ctx *core.FileContext, checker FuncDeclChecker) []*core.Violation
AnalyzeFuncDecls is a helper for rules that need full function declarations. Use this when you need function name, receiver, etc. in addition to body.
func AnalyzeGoAndFrontend ¶
func AnalyzeGoAndFrontend( ctx *core.FileContext, analyzeGo func(*core.FileContext) []*core.Violation, analyzeFrontend func(*core.FileContext) []*core.Violation, ) []*core.Violation
AnalyzeGoAndFrontend dispatches a file to its language-specific analyzer.
func IsInComment ¶
IsInComment checks if a substring appears inside a comment.
func IsInStringOrComment ¶
IsInStringOrComment checks if a substring is inside a string literal or comment.
func IsInsideBackticks ¶
IsInsideBackticks checks if a substring appears inside a backtick (raw) string literal.
func IsInsideString ¶
IsInsideString checks if a substring appears inside a double-quoted string literal. It counts quotes before the substring - odd count means inside a string.
Types ¶
type FuncBodyChecker ¶
type FuncBodyChecker func(ctx *core.FileContext, body *ast.BlockStmt, violations *[]*core.Violation)
FuncBodyChecker is called for each function body to check for violations. It receives the file context and function body, and appends violations to the provided slice.
type FuncDeclChecker ¶
FuncDeclChecker is called for each function declaration. It receives the file context, function declaration, and returns violations.