Documentation
¶
Overview ¶
Package reporter handles formatting and outputting analysis results.
The reporter package provides a flexible reporting interface that can output analysis results in different formats. Currently supports console output with formatted tables and sections.
Output Format ¶
The console reporter outputs: - Summary statistics (files, lines, functions) - Aggregate metrics (averages, percentiles, comment ratio) - Issues grouped by severity (warnings, info) - Test coverage report (if enabled) - Dependency analysis (if enabled) - Top N largest files and most complex functions
Usage ¶
Create a console reporter:
cfg := &config.OutputConfig{
Format: "console",
Verbose: true,
}
reporter, err := reporter.NewReporter(cfg)
if err != nil {
log.Fatal(err)
}
Output analysis results:
err = reporter.Report(analysisResult)
if err != nil {
log.Fatal(err)
}
Verbose mode includes additional details like full file paths and detailed issue descriptions.
Index ¶
- func CreateOutputFile(path string) (*os.File, error)
- type ChartData
- type ComplexityDistribution
- type ConsoleReporter
- type CoverageBreakdownData
- type DependencyGraphData
- type GraphEdge
- type GraphNode
- type HTMLReporter
- type HeatmapCell
- type IssueCountData
- type JSONOutput
- type JSONReporter
- type MarkdownReporter
- type MetricsTimeSeriesData
- type Reporter
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ChartData ¶ added in v1.1.0
type ChartData struct {
ComplexityDist *ComplexityDistribution `json:"complexityDist"`
CoverageBreakdown *CoverageBreakdownData `json:"coverageBreakdown"`
IssueCounts *IssueCountData `json:"issueCounts"`
Heatmap []*HeatmapCell `json:"heatmap"`
DependencyGraph *DependencyGraphData `json:"dependencyGraph"`
MetricsTimeSeries *MetricsTimeSeriesData `json:"metricsTimeSeries,omitempty"`
}
ChartData contains all pre-processed data for JavaScript charts
type ComplexityDistribution ¶ added in v1.1.0
type ComplexityDistribution struct {
Ranges []string `json:"ranges"` // ["1-5", "6-10", "11-15", "16-20", "20+"]
Counts []int `json:"counts"` // Number of functions in each range
}
ComplexityDistribution for histogram showing function complexity distribution
type ConsoleReporter ¶
type ConsoleReporter struct {
// contains filtered or unexported fields
}
ConsoleReporter implements Reporter for console output.
This reporter formats analysis results for terminal display with: - Colored severity indicators (❌/⚠️/ℹ️) - Formatted tables for metrics and comparisons - Verbose mode for detailed per-file breakdowns - Historical comparison summaries (Phase 3)
The output is organized into logical sections: 1. Header with project info and timestamp 2. Comparison summary (if previous report exists) 3. Summary statistics 4. Aggregate metrics 5. Issues list (sorted by severity) 6. Largest files 7. Most complex functions 8. Test coverage report 9. Dependency analysis 10. Detailed comparison (verbose mode) 11. Per-file details (verbose mode)
Printing logic is split across: - console.go (this file): Main struct and Report() orchestration - console_printers.go: Individual section print methods - console_formatters.go: Formatting helper functions
func NewConsoleReporter ¶
func NewConsoleReporter(cfg *config.OutputConfig) *ConsoleReporter
NewConsoleReporter creates a new ConsoleReporter with the given configuration.
func (*ConsoleReporter) Report ¶
func (cr *ConsoleReporter) Report(result *analyzer.AnalysisResult, comp *comparison.ComparisonResult) error
Report outputs the analysis results to the console.
This is the main orchestration method that coordinates all report sections. It sorts issues by severity, prints a formatted header, then delegates to specialized print methods for each section.
The report structure adapts based on: - Available data (coverage, dependencies, comparison) - Verbose mode setting - Issue count
type CoverageBreakdownData ¶ added in v1.1.0
type CoverageBreakdownData struct {
Packages []string `json:"packages"` // Package names
Coverages []float64 `json:"coverages"` // Coverage percentages
Colors []string `json:"colors"` // Color codes based on threshold
}
CoverageBreakdownData for per-package coverage visualization
type DependencyGraphData ¶ added in v1.1.0
type DependencyGraphData struct {
Nodes []GraphNode `json:"nodes"`
Edges []GraphEdge `json:"edges"`
}
DependencyGraphData for network visualization
type GraphEdge ¶ added in v1.1.0
type GraphEdge struct {
From string `json:"from"`
To string `json:"to"`
Color string `json:"color,omitempty"` // Red for circular deps
Width int `json:"width"` // 1-3
}
GraphEdge represents a dependency relationship
type GraphNode ¶ added in v1.1.0
type GraphNode struct {
ID string `json:"id"`
Label string `json:"label"`
Group string `json:"group"` // "stdlib", "internal", "external"
Value int `json:"value"` // Size based on import count
Title string `json:"title"` // Tooltip text
}
GraphNode represents a package in the dependency graph
type HTMLReporter ¶ added in v1.1.0
type HTMLReporter struct {
// contains filtered or unexported fields
}
HTMLReporter implements Reporter for HTML dashboard output
func NewHTMLReporter ¶ added in v1.1.0
func NewHTMLReporter(cfg *config.OutputConfig) *HTMLReporter
NewHTMLReporter creates a new HTMLReporter
func (*HTMLReporter) Report ¶ added in v1.1.0
func (hr *HTMLReporter) Report(result *analyzer.AnalysisResult, comp *comparison.ComparisonResult) error
Report generates an HTML formatted dashboard report
func (*HTMLReporter) WithStorage ¶ added in v1.1.0
func (hr *HTMLReporter) WithStorage(store storage.Storage) *HTMLReporter
WithStorage sets the storage for historical trend analysis
type HeatmapCell ¶ added in v1.1.0
type HeatmapCell struct {
FilePath string `json:"filePath"` // Relative file path
FileName string `json:"fileName"` // Just the filename
Complexity float64 `json:"complexity"` // Average complexity
LOC int `json:"loc"` // Lines of code
Functions int `json:"functions"` // Number of functions
Color string `json:"color"` // Color based on complexity
Size int `json:"size"` // Relative size for grid (1-5)
}
HeatmapCell represents a single file in the complexity heatmap
type IssueCountData ¶ added in v1.1.0
type IssueCountData struct {
Types []string `json:"types"` // Issue type labels
ErrorCount []int `json:"errorCount"` // Count of errors per type
WarnCount []int `json:"warnCount"` // Count of warnings per type
InfoCount []int `json:"infoCount"` // Count of info per type
}
IssueCountData for stacked bar chart showing issues by type and severity
type JSONOutput ¶ added in v0.3.0
type JSONOutput struct {
Timestamp string `json:"timestamp"`
Version string `json:"version"`
Result *analyzer.AnalysisResult `json:"result"`
Comparison *comparison.ComparisonResult `json:"comparison,omitempty"` // Phase 3: Optional comparison
}
JSONOutput wraps the analysis result with metadata for JSON export
type JSONReporter ¶ added in v0.3.0
type JSONReporter struct {
// contains filtered or unexported fields
}
JSONReporter implements Reporter for JSON output
func NewJSONReporter ¶ added in v0.3.0
func NewJSONReporter(cfg *config.OutputConfig) *JSONReporter
NewJSONReporter creates a new JSONReporter
func (*JSONReporter) Report ¶ added in v0.3.0
func (jr *JSONReporter) Report(result *analyzer.AnalysisResult, comp *comparison.ComparisonResult) error
Report generates a JSON formatted report
type MarkdownReporter ¶ added in v0.3.0
type MarkdownReporter struct {
// contains filtered or unexported fields
}
MarkdownReporter implements Reporter for Markdown output
func NewMarkdownReporter ¶ added in v0.3.0
func NewMarkdownReporter(cfg *config.OutputConfig) *MarkdownReporter
NewMarkdownReporter creates a new MarkdownReporter
func (*MarkdownReporter) Report ¶ added in v0.3.0
func (mr *MarkdownReporter) Report(result *analyzer.AnalysisResult, comp *comparison.ComparisonResult) error
Report generates a Markdown formatted report
type MetricsTimeSeriesData ¶ added in v1.1.0
type MetricsTimeSeriesData struct {
Labels []string `json:"labels"` // Timestamps (formatted)
Complexity []float64 `json:"complexity"` // Average complexity over time
Coverage []float64 `json:"coverage"` // Coverage percentage over time
IssueCount []int `json:"issueCount"` // Total issues over time
TotalLines []int `json:"totalLines"` // Total lines of code over time
RawTimestamps []string `json:"timestamps"` // ISO timestamps for tooltips
}
MetricsTimeSeriesData for line chart showing metrics over time
type Reporter ¶
type Reporter interface {
// Report formats and outputs the analysis results.
//
// The result parameter contains all analysis data including issues,
// metrics, coverage, and dependencies.
//
// The comparison parameter (Phase 3) contains comparison with previous
// report if available. Can be nil if no previous report exists or
// comparison is disabled.
//
// The implementation determines how this data is formatted and where it's sent.
//
// Returns an error if output fails (e.g., I/O error, formatting error).
Report(result *analyzer.AnalysisResult, comparison *comparison.ComparisonResult) error
}
Reporter defines the interface for formatting and outputting analysis results.
Implementations of this interface are responsible for:
- Formatting the AnalysisResult into the desired output format
- Including comparison data if available (Phase 3)
- Writing the formatted output to the appropriate destination
- Handling output errors gracefully
The analyzer package is output-agnostic; all formatting decisions are delegated to Reporter implementations.
func NewReporter ¶
func NewReporter(cfg *config.OutputConfig) (Reporter, error)
NewReporter creates a new Reporter based on the configured output format.
Supported formats:
- "console" (default): Human-readable console output with tables
- "markdown": GitHub-flavored Markdown with tables and sections
- "json": JSON output for programmatic consumption
- "html": Interactive HTML dashboard with charts and visualizations
Returns an error if the configured format is not supported.
type TemplateData ¶ added in v1.1.0
type TemplateData struct {
// Basic info
ProjectPath string
ProjectName string
Timestamp string
Duration string
// Summary metrics
TotalFiles int
TotalLines int
TotalCodeLines int
CodePercent float64
CommentLines int
CommentPercent float64
BlankLines int
BlankPercent float64
TotalFunctions int
// Aggregate metrics
Metrics *analyzer.AggregateMetrics
// Issues
Issues []*analyzer.Issue
IssueCount int
ErrorCount int
WarningCount int
InfoCount int
// Coverage
Coverage *analyzer.CoverageReport
// Dependencies
Dependencies *analyzer.DependencyReport
// Comparison
Comparison *comparison.ComparisonResult
// Chart data
ChartData *ChartData
ChartDataJSON template.JS
// Files (verbose mode)
Files []*analyzer.FileAnalysis
Verbose bool
}
TemplateData contains all data needed for the HTML template