evidence

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeGoComplexity

func ComputeGoComplexity(src string) map[string]int

ComputeGoComplexity parses Go source and returns cyclomatic complexity per function. Key: function name (or Receiver.Method for methods). Value: complexity.

func CoverageForFile added in v0.4.0

func CoverageForFile(cm CoverageMap, filePath string) float64

CoverageForFile returns the coverage ratio (0.0–1.0) for a specific file. Returns -1 if the file is not found in the coverage map.

func ParseCoberturaXML added in v0.12.0

func ParseCoberturaXML(content string) float64

ParseCoberturaXML parses Cobertura XML and returns coverage as 0.0-1.0.

func ParseCoverProfile

func ParseCoverProfile(profile string) float64

ParseCoverProfile parses a Go coverage profile and returns coverage as 0.0-1.0.

func ParseLCOV added in v0.12.0

func ParseLCOV(content string) float64

ParseLCOV parses LCOV coverage format and returns coverage as 0.0-1.0.

func UnitBelongsToModule added in v0.12.0

func UnitBelongsToModule(unitPath string, module ModuleRoot) bool

UnitBelongsToModule checks if a unit path (relative to repo root) falls within a module's directory.

Types

type CodeMetrics

type CodeMetrics struct {
	TotalLines   int `json:"total_lines"`
	BlankLines   int `json:"blank_lines"`
	CommentLines int `json:"comment_lines"`
	CodeLines    int `json:"code_lines"`
	TodoCount    int `json:"todo_count"`
	Complexity   int `json:"complexity"`
}

CodeMetrics holds basic code metrics for a file or symbol.

func ComputeMetrics

func ComputeMetrics(src string) CodeMetrics

ComputeMetrics computes basic code metrics from source text.

func ComputeSymbolMetrics

func ComputeSymbolMetrics(src, symbol string) CodeMetrics

ComputeSymbolMetrics computes metrics for a specific symbol within Go source. If the symbol isn't found, falls back to file-level metrics.

func (CodeMetrics) ToEvidence

func (m CodeMetrics) ToEvidence() domain.Evidence

ToEvidence converts CodeMetrics to a domain.Evidence.

type CoverageMap added in v0.4.0

type CoverageMap map[string]FileCoverage

CoverageMap maps file paths to their aggregated coverage data.

func ParseCoverProfilePerFunc added in v0.4.0

func ParseCoverProfilePerFunc(profile string) CoverageMap

ParseCoverProfilePerFunc parses a Go coverage profile and returns per-file coverage data. The profile format is:

mode: set
file:startline.col,endline.col numstatements count

type FileCoverage added in v0.4.0

type FileCoverage struct {
	Statements int // Total statements in coverage blocks
	Covered    int // Statements with count > 0
}

FileCoverage holds aggregated coverage data for a single file.

type FileMetrics added in v0.5.0

type FileMetrics struct {
	HasInitFunc        bool
	GlobalMutableCount int
}

FileMetrics holds file-level structural analysis results.

func AnalyzeGoFile added in v0.5.0

func AnalyzeGoFile(src string) FileMetrics

AnalyzeGoFile performs file-level structural analysis. Detects init() functions and package-level mutable vars.

type GitStats

type GitStats struct {
	CommitCount int `json:"commit_count"`
	AuthorCount int `json:"author_count"`
	AgeDays     int `json:"age_days"`
}

GitStats holds parsed git history data for a file.

func ParseGitLog

func ParseGitLog(output string) GitStats

ParseGitLog parses tab-separated git log output (hash\tauthor\tdate).

func ParseGitLogWithAge

func ParseGitLogWithAge(output string, earliestDate string) GitStats

ParseGitLogWithAge parses git log output and computes age from the earliest date.

func (GitStats) ChurnRate

func (s GitStats) ChurnRate() float64

ChurnRate returns commits per day. Returns 0 if age is zero.

func (GitStats) ToEvidence

func (s GitStats) ToEvidence() domain.Evidence

ToEvidence converts GitStats to a domain.Evidence.

type LintFinding

type LintFinding struct {
	File     string `json:"file"`
	Line     int    `json:"line"`
	Message  string `json:"message"`
	Severity string `json:"severity"`
	Rule     string `json:"rule,omitempty"`
}

LintFinding represents a single lint finding.

type LintResult

type LintResult struct {
	Tool       string        `json:"tool"`
	ErrorCount int           `json:"error_count"`
	WarnCount  int           `json:"warn_count"`
	Findings   []LintFinding `json:"findings,omitempty"`
}

LintResult holds aggregated lint results.

func AttributeLintToFile added in v0.4.0

func AttributeLintToFile(findings []LintFinding, filePath string) LintResult

AttributeLintToFile filters lint findings to those belonging to a specific file and returns a LintResult scoped to that file.

func AttributeLintToUnit added in v0.4.0

func AttributeLintToUnit(findings []LintFinding, filePath string, startLine, endLine int) LintResult

AttributeLintToUnit filters lint findings to those within a specific file and line range [startLine, endLine] inclusive.

func ParseCargoClippyJSON added in v0.12.0

func ParseCargoClippyJSON(output string) LintResult

ParseCargoClippyJSON parses cargo clippy --message-format=json output.

func ParseESLintJSON added in v0.12.0

func ParseESLintJSON(output string) LintResult

ParseESLintJSON parses ESLint JSON output into a LintResult.

func ParseGoVet

func ParseGoVet(stderr string, exitCode int) LintResult

ParseGoVet parses go vet stderr output into a LintResult.

func ParseGolangciLintJSON

func ParseGolangciLintJSON(output string) LintResult

ParseGolangciLintJSON parses golangci-lint JSON output into a LintResult.

func ParseRuffJSON added in v0.12.0

func ParseRuffJSON(output string) LintResult

ParseRuffJSON parses ruff JSON output (one object per line) into a LintResult.

func (LintResult) ToEvidence

func (r LintResult) ToEvidence() domain.Evidence

ToEvidence converts LintResult to a domain.Evidence.

type ModuleRoot added in v0.12.0

type ModuleRoot struct {
	Path     string // Absolute path to the module directory
	RelPath  string // Relative path from repo root (empty = repo root)
	Language string // "go", "ts", "py", "rs", etc.
	Marker   string // The file that identified this as a module root (go.mod, package.json, etc.)
}

ModuleRoot represents a discovered language module root directory.

func DiscoverModuleRoots added in v0.12.0

func DiscoverModuleRoots(repoRoot string) []ModuleRoot

DiscoverModuleRoots walks from the repository root and finds all directories that contain language module markers (go.mod, package.json, Cargo.toml, etc.).

This handles monorepos and nested modules: a Go project might have go.mod in code/, services/api/, or multiple locations. Each is returned as a ModuleRoot.

func FindModuleForUnit added in v0.12.0

func FindModuleForUnit(unitPath string, modules []ModuleRoot) *ModuleRoot

FindModuleForUnit returns the most specific module root that contains the given unit path. Returns nil if no module contains the unit.

func GoModuleRoots added in v0.12.0

func GoModuleRoots(roots []ModuleRoot) []ModuleRoot

GoModuleRoots returns only Go module roots from the discovered modules.

type StructuralMetrics added in v0.4.0

type StructuralMetrics struct {
	HasDocComment   bool   // Exported func/type has a preceding doc comment
	ParamCount      int    // Number of function parameters (excluding receiver)
	ReturnCount     int    // Number of return values
	MaxNestingDepth int    // Deepest nesting level within the function body
	NakedReturns    int    // Count of bare return statements in named-return functions
	ErrorsIgnored   int    // Count of blank identifier assignments to error-typed returns
	ExportedName    bool   // Symbol starts with uppercase
	ReceiverName    string // Receiver type name (empty for standalone functions)
	IsConstructor   bool   // Function name matches New* pattern

	// Tier 1: new metrics
	FuncLines          int  // Number of lines in function body
	PanicCalls         int  // Count of panic() calls
	OsExitCalls        int  // Count of os.Exit() calls
	DeferInLoop        int  // Count of defer statements inside for/range loops
	ContextNotFirst    bool // context.Context param exists but is not the first param
	MethodCount        int  // Number of methods on a type (type-level only)
	HasInitFunc        bool // File contains an init() function (file-level only)
	GlobalMutableCount int  // Number of package-level var declarations (file-level only)

	// Algorithmic complexity metrics
	AlgoComplexity    string // Estimated complexity class: O(1), O(n), O(n²), O(n³), O(2^n)
	LoopNestingDepth  int    // Maximum depth of nested loops (for/range only)
	RecursiveCalls    int    // Count of direct recursive calls (func calls own name)
	NestedLoopPairs   int    // Count of inner loops nested inside outer loops
	QuadraticPatterns int    // Count of known O(n²) anti-patterns
}

StructuralMetrics holds AST-derived structural analysis results for a code unit.

func AnalyzeGoFunc added in v0.4.0

func AnalyzeGoFunc(src string, funcName string) StructuralMetrics

AnalyzeGoFunc parses Go source and analyzes a function or method by name. Returns zero-value StructuralMetrics if the source can't be parsed or symbol not found.

func AnalyzeGoType added in v0.4.0

func AnalyzeGoType(src string, typeName string) StructuralMetrics

AnalyzeGoType parses Go source and analyzes a type declaration by name.

func (StructuralMetrics) ToEvidence added in v0.4.0

func (m StructuralMetrics) ToEvidence() domain.Evidence

ToEvidence converts StructuralMetrics to a domain.Evidence.

type TestResult

type TestResult struct {
	Tool        string  `json:"tool"`
	TotalCount  int     `json:"total_count"`
	PassedCount int     `json:"passed_count"`
	FailedCount int     `json:"failed_count"`
	SkipCount   int     `json:"skip_count"`
	Coverage    float64 `json:"coverage"` // 0.0–1.0
}

TestResult holds aggregated test execution results.

func ParseCargoTestOutput added in v0.12.0

func ParseCargoTestOutput(output string) TestResult

ParseCargoTestOutput parses cargo test stdout for test counts. Format: "test result: ok. 42 passed; 0 failed; 0 ignored; ..."

func ParseGoTestJSON

func ParseGoTestJSON(output string) TestResult

ParseGoTestJSON parses `go test -json` output into a TestResult.

func ParseJestJSON added in v0.12.0

func ParseJestJSON(output string) TestResult

ParseJestJSON parses Jest JSON output into a TestResult.

func ParsePytestJUnitXML added in v0.12.0

func ParsePytestJUnitXML(output string) TestResult

ParsePytestJUnitXML parses pytest JUnit XML output.

func ParsePytestShort added in v0.12.0

func ParsePytestShort(output string) TestResult

ParsePytestShort parses pytest short summary output for fallback. Matches patterns like "5 passed", "2 failed", "1 skipped"

func (TestResult) ToEvidence

func (r TestResult) ToEvidence() domain.Evidence

ToEvidence converts TestResult to a domain.Evidence.

type ToolExecutor

type ToolExecutor struct {
	// contains filtered or unexported fields
}

ToolExecutor runs external tools and collects evidence. After CollectAll(), raw lint findings and coverage profile are retained for per-unit attribution by the certification pipeline.

ToolExecutor discovers nested module roots (go.mod in subdirectories) and runs tools from each module root. This supports monorepos and repos where the Go module is not at the repository root.

func NewToolExecutor

func NewToolExecutor(root string) *ToolExecutor

NewToolExecutor creates a tool executor rooted at the given directory. It discovers all module roots (go.mod, package.json, etc.) in the tree.

func (*ToolExecutor) CollectAll

func (te *ToolExecutor) CollectAll() []domain.Evidence

CollectAll runs all available tool runners and returns collected evidence. Discovers module roots and runs language-appropriate tools from each.

func (*ToolExecutor) CoverageProfile added in v0.4.0

func (te *ToolExecutor) CoverageProfile() string

CoverageProfile returns the raw Go coverage profile collected during CollectAll(). Returns empty string if coverage was not collected.

func (*ToolExecutor) HasGoMod

func (te *ToolExecutor) HasGoMod() bool

HasGoMod returns true if any discovered module root is a Go module.

func (*ToolExecutor) HasPackageJSON

func (te *ToolExecutor) HasPackageJSON() bool

HasPackageJSON returns true if the root has a package.json.

func (*ToolExecutor) LintFindings added in v0.4.0

func (te *ToolExecutor) LintFindings() []LintFinding

LintFindings returns all lint findings collected during CollectAll(). Returns nil if no lint tools were run or found no issues.

func (*ToolExecutor) ModuleRoots added in v0.12.0

func (te *ToolExecutor) ModuleRoots() []ModuleRoot

ModuleRoots returns the discovered module roots.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL