Documentation
¶
Overview ¶
Package analysis provides language-agnostic code analysis through a unified interface. Each language implements the Analyzer interface, producing consistent structural metrics that feed into the certification scoring pipeline.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Analyzer ¶
type Analyzer interface {
// Language returns the language identifier (e.g., "go", "ts", "py").
Language() string
// Discover finds all symbols in a source file.
Discover(path string, src []byte) ([]Symbol, error)
// Analyze returns structural metrics for a specific symbol.
Analyze(path string, src []byte, symbol string) (Metrics, error)
// AnalyzeFile returns file-level metrics.
AnalyzeFile(path string, src []byte) (FileMetrics, error)
}
Analyzer provides language-agnostic structural analysis.
func ForLanguage ¶
ForLanguage returns an Analyzer for the given language, or nil if unsupported.
type FileMetrics ¶
FileMetrics holds file-level analysis results.
type GoAnalyzer ¶
type GoAnalyzer struct{}
GoAnalyzer implements Analyzer for Go source code using go/ast.
func (*GoAnalyzer) AnalyzeFile ¶
func (a *GoAnalyzer) AnalyzeFile(path string, src []byte) (FileMetrics, error)
AnalyzeFile returns file-level metrics.
func (*GoAnalyzer) Discover ¶
func (a *GoAnalyzer) Discover(path string, src []byte) ([]Symbol, error)
Discover finds all functions, methods, and types in Go source.
func (*GoAnalyzer) Language ¶
func (a *GoAnalyzer) Language() string
type Metrics ¶
type Metrics struct {
// Shape
ParamCount int // Number of function parameters
ReturnCount int // Number of return values
FuncLines int // Lines in function body
MaxNestingDepth int // Deepest nesting level (if/for/switch/etc.)
// Documentation
HasDocComment bool // Has a doc comment
IsExported bool // Exported / public symbol
ReceiverName string // Receiver type name (empty for standalone)
IsConstructor bool // Matches constructor pattern (New*, __init__, constructor)
// Complexity
CyclomaticComplexity int // McCabe cyclomatic complexity
CognitiveComplexity int // Sonar-style cognitive complexity
LoopNestingDepth int // Max nested loop depth (for/while only)
RecursiveCalls int // Direct recursive calls
AlgoComplexity string // Estimated Big-O: O(1), O(n), O(n²), etc.
// Error handling
ErrorsIgnored int // Discarded error returns
ErrorsNotWrapped int // Errors returned without wrapping/context
NakedReturns int // Bare return in named-return function
PanicCalls int // panic(), throw, unwrap() — unrecoverable exits
EmptyCatchBlocks int // catch/except/recover with empty body
// Security
UnsafeImports []string // Dangerous imports (os/exec, unsafe, eval, etc.)
HardcodedSecrets int // String literals matching secret patterns
// Design
MethodCount int // Methods on a type (type-level only)
DeferInLoop int // Defer/finally inside loops
ContextNotFirst bool // context.Context not first param (Go-specific)
// Performance
NestedLoopPairs int // Inner loops nested in outer loops
QuadraticPatterns int // Known O(n²) anti-patterns
// File-level
HasInitFunc bool // File contains init() or equivalent
GlobalMutableCount int // Package-level mutable variables
OsExitCalls int // os.Exit() or sys.exit() calls
// Language-specific extras
Extra map[string]float64
}
Metrics holds language-agnostic structural analysis results for a code unit.
func (Metrics) ToEvidence ¶
ToEvidence converts Metrics to a domain.Evidence for the scoring pipeline.
type PythonAnalyzer ¶
type PythonAnalyzer struct {
// contains filtered or unexported fields
}
PythonAnalyzer implements Analyzer for Python using tree-sitter.
func NewPythonAnalyzer ¶
func NewPythonAnalyzer() *PythonAnalyzer
NewPythonAnalyzer creates a new Python analyzer.
func (*PythonAnalyzer) AnalyzeFile ¶
func (a *PythonAnalyzer) AnalyzeFile(path string, src []byte) (FileMetrics, error)
AnalyzeFile returns file-level metrics.
func (*PythonAnalyzer) Discover ¶
func (a *PythonAnalyzer) Discover(path string, src []byte) ([]Symbol, error)
Discover finds all symbols in Python source.
func (*PythonAnalyzer) Language ¶
func (a *PythonAnalyzer) Language() string
type RustAnalyzer ¶
type RustAnalyzer struct {
// contains filtered or unexported fields
}
RustAnalyzer implements Analyzer for Rust using tree-sitter.
func NewRustAnalyzer ¶
func NewRustAnalyzer() *RustAnalyzer
NewRustAnalyzer creates a new Rust analyzer.
func (*RustAnalyzer) AnalyzeFile ¶
func (a *RustAnalyzer) AnalyzeFile(path string, src []byte) (FileMetrics, error)
AnalyzeFile returns file-level metrics.
func (*RustAnalyzer) Discover ¶
func (a *RustAnalyzer) Discover(path string, src []byte) ([]Symbol, error)
Discover finds all symbols in Rust source.
func (*RustAnalyzer) Language ¶
func (a *RustAnalyzer) Language() string
type Symbol ¶
type Symbol struct {
Name string // Symbol name
Kind SymbolKind // Function, method, class, etc.
StartLine int // 1-indexed start line
EndLine int // 1-indexed end line (inclusive)
Parent string // Enclosing type/class name (empty for top-level)
Exported bool // Whether the symbol is exported/public
}
Symbol represents a discovered code unit within a source file.
type SymbolKind ¶
type SymbolKind int
SymbolKind identifies the type of a discovered code symbol.
const ( SymbolFunction SymbolKind = iota // Standalone function SymbolMethod // Method on a type/class SymbolClass // Type, class, struct, interface SymbolConstant // Exported constant or variable SymbolInterface // Interface (separate from class for languages that distinguish) )
func (SymbolKind) String ¶
func (k SymbolKind) String() string
type TSAnalyzer ¶
type TSAnalyzer struct {
// contains filtered or unexported fields
}
TSAnalyzer implements Analyzer for TypeScript using tree-sitter.
func NewTSAnalyzer ¶
func NewTSAnalyzer() *TSAnalyzer
NewTSAnalyzer creates a new TypeScript analyzer.
func (*TSAnalyzer) AnalyzeFile ¶
func (a *TSAnalyzer) AnalyzeFile(path string, src []byte) (FileMetrics, error)
AnalyzeFile returns file-level metrics.
func (*TSAnalyzer) Discover ¶
func (a *TSAnalyzer) Discover(path string, src []byte) ([]Symbol, error)
Discover finds all symbols in a TypeScript source file.
func (*TSAnalyzer) Language ¶
func (a *TSAnalyzer) Language() string