reporter

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

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 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

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

Report generates a Markdown formatted report

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

Returns an error if the configured format is not supported.

Jump to

Keyboard shortcuts

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