Documentation
¶
Index ¶
- Constants
- Variables
- func Classify(score int) string
- func DetectIndentSize(lines []string) int
- func DetectedLanguage(ext string) string
- func TestClassifyHelper(score int) string
- func TierReferenceTable() string
- func VulnClassify(findings []struct{ ... }) string
- type BumpRange
- type BumpyRoadResult
- type CohesionResult
- type ComplexityCount
- type DuplicationPair
- type FunctionBloat
- func DetectFunctionBloats(lines []string) []FunctionBloat
- func DetectFunctionBloatsCPP(lines []string) []FunctionBloat
- func DetectFunctionBloatsIndent(lines []string, indentSize int) []FunctionBloat
- func DetectFunctionBloatsJava(lines []string) []FunctionBloat
- func DetectFunctionBloatsKotlin(lines []string) []FunctionBloat
- func DetectFunctionBloatsRuby(lines []string) []FunctionBloat
- func DetectFunctionBloatsRust(lines []string) []FunctionBloat
- func DetectFunctionBloatsSwift(lines []string) []FunctionBloat
- func DetectFunctionBloatsTS(lines []string) []FunctionBloat
- type GitHotspotResult
- type HotspotEntry
- type NestingResult
- type QualityResult
- type ScoreTier
- type Smell
- func DetectBrainMethodSmell(bloats []FunctionBloat, warningThreshold int, alertThreshold int) []Smell
- func DetectBumpyRoadSmell(lines []string, bumpDepth int, bumpsWarning int) *Smell
- func DetectBumpyRoadSmellAt(lines []string, bumpDepth int, bumpsWarning int, funcStartLine int) *Smell
- func DetectComplexConditional(lines []string, warningThreshold int, alertThreshold int) []Smell
- func DetectDuplicationSmells(pairs []DuplicationPair) []Smell
- func DetectExcessiveComments(lines []string, ratioThreshold float64) *Smell
- func DetectFileBloat(totalLoc int, warningThreshold int, alertThreshold int, criticalThreshold int) *Smell
- func DetectGlobalData(lines []string, minGlobals int) *Smell
- func DetectHotspotSmell(entry HotspotEntry) *Smell
- func DetectLazyElements(bloats []FunctionBloat, minLines int) []Smell
- func DetectLongParameterList(lines []string, warningThreshold int, alertThreshold int) []Smell
- func DetectLongScopeVariables(lines []string, bloats []FunctionBloat, minLineGap int) []Smell
- func DetectLongSwitch(lines []string, warnThreshold int, alertThreshold int) []Smell
- func DetectLowCohesionSmell(result CohesionResult, warningThreshold int, badThreshold int) *Smell
- func DetectMessageChains(lines []string) []Smell
- func DetectNestingSmell(lines []string, warningThreshold int, alertThreshold int) *Smell
- func DetectParagraphOfCode(lines []string, maxConsecutive int) []Smell
- func DetectPrimitiveObsession(lines []string) []Smell
- type Thresholds
Constants ¶
const ( LabelGoAhead = "Go Ahead" LabelProceedWithCare = "Proceed with Care" LabelNeedsWork = "Needs Work" LabelStopRefactor = "Stop & Refactor" )
Tiers for code quality score classification.
const ( GoAheadThreshold = 80 ProceedWithCareThreshold = 60 NeedsWorkThreshold = 40 )
Score tier thresholds — single source of truth for the classify() function. Templates reference these so they auto-update when tiers change.
const ( VulnLabelClean = "Clean" VulnLabelMonitor = "Monitor" VulnLabelRemediate = "Remediate" )
Tiers for vulnerability severity classification.
Variables ¶
var ChainPattern = regexp.MustCompile(`\.\w+\([^)]*\)\.\w+\(`)
ChainPattern matches method chains like a.b().c()
Functions ¶
func DetectIndentSize ¶
DetectIndentSize auto-detects whether a file uses spaces or tabs for indentation.
func DetectedLanguage ¶
DetectedLanguage maps a file extension to a language name.
func TestClassifyHelper ¶
TestClassifyHelper is exported for testing the classify function.
func TierReferenceTable ¶ added in v0.8.9
func TierReferenceTable() string
TierReferenceTable returns a markdown table of score tiers for inclusion in AGENTS.md and agent configuration templates.
func VulnClassify ¶ added in v0.8.2
VulnClassify returns a vulnerability tier based on findings.
Types ¶
type BumpRange ¶
type BumpRange struct {
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
MaxDepth int `json:"max_depth"`
LineCount int `json:"line_count"`
}
BumpRange represents one "bump" in a nesting sprawl.
type BumpyRoadResult ¶
type BumpyRoadResult struct {
Bumps []BumpRange `json:"bumps"`
IsBumpyRoad bool `json:"is_bumpy_road"`
Severity string `json:"severity"` // "ok", "warning", "alert", "critical"
MaxDepth int `json:"max_depth"`
}
BumpyRoadResult holds the output of a nesting sprawl analysis on one function.
func DetectBumpyRoadForFunction ¶
func DetectBumpyRoadForFunction(lines []string, bumpDepthThreshold int, bumpsWarning int) BumpyRoadResult
DetectBumpyRoadForFunction analyzes indentation within a function body.
type CohesionResult ¶
type CohesionResult struct {
TotalFuncs int
IsolatedFuncs int
CohesionScore float64 // 0-1, higher = more cohesive
IsLowCohesion bool
}
CohesionResult describes module-level cohesion.
func AnalyzeCohesion ¶
func AnalyzeCohesion(bloats []FunctionBloat, lines []string) CohesionResult
AnalyzeCohesion estimates module cohesion by checking how many functions share common types in their signatures (parameters, returns). Low cohesion: many isolated functions that don't share types with others.
type ComplexityCount ¶
Complexity counts branches (if, for, while, &&, ||) in source lines.
func CountBranches ¶
func CountBranches(lines []string) []ComplexityCount
CountBranches counts control-flow branches in a set of lines (e.g., a function body).
type DuplicationPair ¶
type DuplicationPair struct {
FuncA string
FuncB string
LineA int
LineB int
Similarity float64
LineCount int
}
DuplicationPair represents a pair of duplicated code regions.
func DetectDuplications ¶
func DetectDuplications(bloats []FunctionBloat, lines []string, minLines int, minSimilarity float64) []DuplicationPair
DetectDuplications checks for duplicated code across function bodies. Uses normalized fingerprint comparison with configurable minimum similarity.
type FunctionBloat ¶
FunctionBloat holds per-function length information.
func DetectFunctionBloats ¶
func DetectFunctionBloats(lines []string) []FunctionBloat
DetectFunctionBloats identifies function boundaries for brace-based languages.
func DetectFunctionBloatsCPP ¶
func DetectFunctionBloatsCPP(lines []string) []FunctionBloat
DetectFunctionBloatsCPP detects C/C++ function boundaries.
func DetectFunctionBloatsIndent ¶
func DetectFunctionBloatsIndent(lines []string, indentSize int) []FunctionBloat
DetectFunctionBloatsIndent detects Python functions using indentation. Handles: def, async def, @decorators, class methods, nested functions, tabs/spaces.
func DetectFunctionBloatsJava ¶
func DetectFunctionBloatsJava(lines []string) []FunctionBloat
DetectFunctionBloatsJava detects Java/C# method boundaries.
func DetectFunctionBloatsKotlin ¶
func DetectFunctionBloatsKotlin(lines []string) []FunctionBloat
DetectFunctionBloatsKotlin detects Kotlin fun boundaries.
func DetectFunctionBloatsRuby ¶
func DetectFunctionBloatsRuby(lines []string) []FunctionBloat
DetectFunctionBloatsRuby detects Ruby def/end boundaries.
func DetectFunctionBloatsRust ¶
func DetectFunctionBloatsRust(lines []string) []FunctionBloat
DetectFunctionBloatsRust detects Rust fn boundaries.
func DetectFunctionBloatsSwift ¶
func DetectFunctionBloatsSwift(lines []string) []FunctionBloat
DetectFunctionBloatsSwift detects Swift func boundaries.
func DetectFunctionBloatsTS ¶
func DetectFunctionBloatsTS(lines []string) []FunctionBloat
DetectFunctionBloatsTS detects functions in JavaScript and TypeScript. Handles: function, async function, export function, class methods, arrow => {. Tracks paren-depth to avoid miscounting destructuring {} inside parameter lists.
type GitHotspotResult ¶
type GitHotspotResult struct {
Entries []HotspotEntry
RepoPath string
Error string
}
GitHotspotResult holds the full hotspot analysis for a repo.
func AnalyzeGitHotspots ¶
func AnalyzeGitHotspots(repoPath string, maxDepth int) GitHotspotResult
AnalyzeGitHotspots scans the git log to find frequently-changed files. Returns files ranked by composite priority (high commits + low health).
func GetCachedHotspots ¶
func GetCachedHotspots(repoPath string, maxDepth int) GitHotspotResult
GetCachedHotspots returns cached hotspot analysis or runs a new one.
type HotspotEntry ¶
type HotspotEntry struct {
FilePath string
CommitCount int
Authors int
Lines int
QualityScore float64
Priority float64 // composite score: commits * (11 - qualityScore)
}
HotspotEntry represents a file with its commit frequency.
type NestingResult ¶
NestingResult holds the outcome of nesting depth analysis.
func AnalyzeNesting ¶
func AnalyzeNesting(lines []string) NestingResult
AnalyzeNesting scans lines and returns the maximum nesting depth found.
type QualityResult ¶
type QualityResult struct {
Score int `json:"score"` // 0-100
Label string `json:"label"` // one of LabelGoAhead, LabelProceedWithCare, LabelNeedsWork, LabelStopRefactor
Smells []Smell `json:"smells"`
FilePath string `json:"file_path"`
Language string `json:"language"`
LinesOfCode int `json:"lines_of_code"`
}
QualityResult is the full output of an analysis.
type ScoreTier ¶ added in v0.8.9
ScoreTier describes one score tier for documentation and templates.
func ScoreTiers ¶ added in v0.8.9
func ScoreTiers() []ScoreTier
ScoreTiers returns all quality score tiers in descending order. Templates call this to generate reference tables that always match the actual classify() function.
type Smell ¶
type Smell struct {
Name string `json:"name"` // e.g. "deep_nesting", "brain_method", "bumpy_road"
Severity string `json:"severity"` // "warning", "alert", "critical"
LineStart int `json:"line_start"`
LineEnd int `json:"line_end"`
Message string `json:"message"` // human-readable description
AIPrompt string `json:"ai_prompt"` // injection text for the LLM
}
Smell represents a detected code smell.
func DetectBrainMethodSmell ¶
func DetectBrainMethodSmell(bloats []FunctionBloat, warningThreshold int, alertThreshold int) []Smell
DetectBrainMethodSmell checks function lengths against thresholds.
func DetectBumpyRoadSmell ¶
DetectBumpyRoadSmell wraps the nesting sprawl result into a Smell.
func DetectBumpyRoadSmellAt ¶
func DetectComplexConditional ¶
DetectComplexConditional checks for if/while conditions with many boolean operators.
func DetectDuplicationSmells ¶
func DetectDuplicationSmells(pairs []DuplicationPair) []Smell
DetectDuplicationSmells converts duplication pairs into Smell entries.
func DetectExcessiveComments ¶
DetectExcessiveComments flag files where comment lines exceed a ratio of total lines.
func DetectFileBloat ¶
func DetectFileBloat(totalLoc int, warningThreshold int, alertThreshold int, criticalThreshold int) *Smell
FileBloatSmell returns a smell if the file exceeds line thresholds.
func DetectGlobalData ¶
DetectGlobalData flags file-level mutable variable declarations outside functions.
func DetectHotspotSmell ¶
func DetectHotspotSmell(entry HotspotEntry) *Smell
DetectHotspotSmell identifies files that are both frequently changed AND unhealthy.
func DetectLazyElements ¶
func DetectLazyElements(bloats []FunctionBloat, minLines int) []Smell
func DetectLongParameterList ¶
DetectLongParameterList checks function signatures for too many parameters.
func DetectLongScopeVariables ¶
func DetectLongScopeVariables(lines []string, bloats []FunctionBloat, minLineGap int) []Smell
DetectLongScopeVariables flags variables declared far from their last usage.
func DetectLongSwitch ¶
func DetectLowCohesionSmell ¶
func DetectLowCohesionSmell(result CohesionResult, warningThreshold int, badThreshold int) *Smell
DetectLowCohesionSmell converts cohesion analysis to a Smell.
func DetectMessageChains ¶
func DetectNestingSmell ¶
DetectNestingSmell checks whether nesting exceeds a threshold and returns a smell if so.
func DetectParagraphOfCode ¶
type Thresholds ¶
type Thresholds struct {
NestingWarning int
NestingAlert int
FileLOCWarning int
FileLOCAlert int
FileLOCCritical int
FuncLOCWarning int
FuncLOCAlert int
FuncCCWarning int
FuncCCAlert int
FuncCountWarning int
FuncCountAlert int
BumpyRoadBumpsWarning int
BumpyRoadNestingDepth int
ComplexCondBranchesWarn int
ComplexCondBranchesAlert int
MaxArgumentsWarn int
MaxArgumentsAlert int
BrainClassMinFunc int
ParagraphMaxConsecutive int
LazyMinLines int
DupMinLines int
DupMinSimilarity float64
CohesionIsolationPct float64
CommentRatioWarning float64
GlobalDataWarning int
LongScopeVarLines int
LongSwitchWarn int
LongSwitchAlert int
}
Thresholds holds the configurable thresholds for all detectors.
func DefaultThresholds ¶
func DefaultThresholds(lang string) Thresholds
DefaultThresholds returns per-language default thresholds.