Documentation
¶
Overview ¶
Package renderer provides section rendering for analyzer reports.
Index ¶
- Constants
- Variables
- func ColorForSeverity(severity string) terminal.Color
- func RegisterPlotRenderer()
- func RenderMetricsJSON(m MetricsOutput) ([]byte, error)
- func RenderMetricsYAML(m MetricsOutput) ([]byte, error)
- func RenderUnifiedModelPlot(model UnifiedModel, writer io.Writer) error
- type AnalyzerResult
- type DefaultStaticRenderer
- func (r *DefaultStaticRenderer) RenderCompact(sections []analyze.ReportSection, noColor bool, writer io.Writer) error
- func (r *DefaultStaticRenderer) RenderText(sections []analyze.ReportSection, verbose, noColor bool, writer io.Writer) error
- func (r *DefaultStaticRenderer) SectionsToJSON(sections []analyze.ReportSection) any
- type ExecutiveSummary
- type JSONDistribution
- type JSONFileEntry
- type JSONIssue
- type JSONMetric
- type JSONReport
- type JSONSection
- type MetricsOutput
- type SectionRenderer
- type UnifiedModel
Constants ¶
const ( CompactBarWidth = 10 CompactTitleWidth = 12 )
Compact mode constants.
const ( IndentWidth = 2 SummaryPrefix = "Summary: " MetricsLabel = "Key Metrics" MetricsPerRow = 2 MetricLabelWidth = 20 MetricValueWidth = 12 DistributionLabel = "Distribution" DistributionBarWidth = 40 DistLabelWidth = 18 IssuesLabel = "Top Issues" AllIssuesLabel = "All Issues" DefaultTopIssues = 5 IssueNameWidth = 25 IssueLocationWidth = 35 )
Render layout constants.
const ( MinSectionsForSummary = 2 SummaryTitle = "CODE ANALYSIS REPORT" SummaryOverallPrefix = "Overall: " SummaryAnalyzerCol = "Analyzer" SummaryScoreCol = "Score" SummaryStatusCol = "Status" SummaryAnalyzerWidth = 16 SummaryScoreWidth = 7 )
Summary constants.
const UnifiedModelVersion = analyze.UnifiedModelVersion
UnifiedModelVersion is the schema version for converted run outputs.
Variables ¶
var ErrInvalidUnifiedModel = analyze.ErrInvalidUnifiedModel
ErrInvalidUnifiedModel indicates malformed canonical conversion data.
var ErrNilMetricsOutput = errors.New("metrics output is nil")
ErrNilMetricsOutput is returned when nil is passed to render functions.
Functions ¶
func ColorForSeverity ¶
ColorForSeverity maps an issue severity string to a terminal color.
func RegisterPlotRenderer ¶
func RegisterPlotRenderer()
RegisterPlotRenderer registers the unified model plot renderer with the analyze package.
func RenderMetricsJSON ¶
func RenderMetricsJSON(m MetricsOutput) ([]byte, error)
RenderMetricsJSON serializes metrics output to JSON bytes.
func RenderMetricsYAML ¶
func RenderMetricsYAML(m MetricsOutput) ([]byte, error)
RenderMetricsYAML serializes metrics output to YAML bytes.
func RenderUnifiedModelPlot ¶
func RenderUnifiedModelPlot(model UnifiedModel, writer io.Writer) error
RenderUnifiedModelPlot renders a canonical model into one combined plot page.
Types ¶
type AnalyzerResult ¶
type AnalyzerResult = analyze.AnalyzerResult
AnalyzerResult is a type alias for analyze.AnalyzerResult so that existing code referencing renderer.AnalyzerResult continues to compile without changes.
type DefaultStaticRenderer ¶
type DefaultStaticRenderer struct{}
DefaultStaticRenderer implements analyze.StaticRenderer using the renderer and terminal packages.
func NewDefaultStaticRenderer ¶
func NewDefaultStaticRenderer() *DefaultStaticRenderer
NewDefaultStaticRenderer creates a DefaultStaticRenderer.
func (*DefaultStaticRenderer) RenderCompact ¶
func (r *DefaultStaticRenderer) RenderCompact( sections []analyze.ReportSection, noColor bool, writer io.Writer, ) error
RenderCompact writes single-line-per-section compact output.
func (*DefaultStaticRenderer) RenderText ¶
func (r *DefaultStaticRenderer) RenderText( sections []analyze.ReportSection, verbose, noColor bool, writer io.Writer, ) error
RenderText writes human-readable text output for the given sections.
func (*DefaultStaticRenderer) SectionsToJSON ¶
func (r *DefaultStaticRenderer) SectionsToJSON(sections []analyze.ReportSection) any
SectionsToJSON converts report sections to a JSON-serializable value. Returns a pointer to enable per-file enrichment via PerFileEnricher interface.
type ExecutiveSummary ¶
type ExecutiveSummary struct {
Sections []analyze.ReportSection
}
ExecutiveSummary holds data for the executive summary report.
func NewExecutiveSummary ¶
func NewExecutiveSummary(sections []analyze.ReportSection) *ExecutiveSummary
NewExecutiveSummary creates an ExecutiveSummary from report sections.
func (*ExecutiveSummary) OverallScore ¶
func (s *ExecutiveSummary) OverallScore() float64
OverallScore returns the average score of all scored sections. Info-only sections (ScoreInfoOnly) are excluded from the average. Returns ScoreInfoOnly if no scored sections exist.
func (*ExecutiveSummary) OverallScoreLabel ¶
func (s *ExecutiveSummary) OverallScoreLabel() string
OverallScoreLabel returns the formatted overall score ("N/10" or "Info").
type JSONDistribution ¶
type JSONDistribution struct {
Label string `json:"label"`
Percent float64 `json:"percent"`
Count int `json:"count"`
}
JSONDistribution is a distribution category in JSON output.
type JSONFileEntry ¶
type JSONFileEntry struct {
FilePath string `json:"file_path"`
ScoreLabel string `json:"score_label"`
Status string `json:"status"`
Metrics []JSONMetric `json:"metrics"`
Distribution []JSONDistribution `json:"distribution,omitempty"`
Issues []JSONIssue `json:"issues"`
Score float64 `json:"score"`
}
JSONFileEntry represents one file's analysis results within a section.
func SectionToJSONFileEntry ¶
func SectionToJSONFileEntry(section analyze.ReportSection, filePath string) JSONFileEntry
SectionToJSONFileEntry converts a ReportSection to a JSONFileEntry for per-file output.
type JSONIssue ¶
type JSONIssue struct {
Name string `json:"name"`
Location string `json:"location"`
Value string `json:"value"`
Severity string `json:"severity"`
}
JSONIssue is a single issue in JSON output.
type JSONMetric ¶
JSONMetric is a key-value metric in JSON output.
type JSONReport ¶
type JSONReport struct {
OverallScoreLabel string `json:"overall_score_label"`
Sections []JSONSection `json:"sections"`
OverallScore float64 `json:"overall_score"`
}
JSONReport is the top-level structured JSON output.
func SectionsToJSON ¶
func SectionsToJSON(sections []analyze.ReportSection) JSONReport
SectionsToJSON converts multiple ReportSections to a JSONReport with overall score.
func (*JSONReport) EnrichWithPerFileData ¶
func (r *JSONReport) EnrichWithPerFileData( perFileResults map[string]map[string]analyze.Report, rootPath string, analyzers []analyze.FormattableAnalyzer, )
EnrichWithPerFileData injects per-file data and summary statistics into JSON sections. Implements analyze.PerFileEnricher to avoid import cycles.
type JSONSection ¶
type JSONSection struct {
Title string `json:"title"`
ScoreLabel string `json:"score_label"`
Status string `json:"status"`
Metrics []JSONMetric `json:"metrics"`
Distribution []JSONDistribution `json:"distribution,omitempty"`
Issues []JSONIssue `json:"issues"`
Files *[]JSONFileEntry `json:"files,omitempty"`
Score float64 `json:"score"`
}
JSONSection represents one analyzer's output in JSON.
func SectionToJSON ¶
func SectionToJSON(section analyze.ReportSection) JSONSection
SectionToJSON converts a ReportSection to a JSONSection.
type MetricsOutput ¶
type MetricsOutput interface {
// AnalyzerName returns the analyzer identifier (e.g., "devs", "burndown").
AnalyzerName() string
// ToJSON returns a struct suitable for JSON marshaling.
// The returned value will be passed to json.Marshal.
ToJSON() any
// ToYAML returns a struct suitable for YAML marshaling.
// The returned value will be passed to yaml.Marshal.
// For most analyzers, this can return the same value as ToJSON.
ToYAML() any
}
MetricsOutput is implemented by analyzer ComputedMetrics structs to provide serializable output for JSON and YAML renderers. This interface establishes the metrics-first pipeline where all output (JSON, YAML, Plot) flows through computed metrics.
type SectionRenderer ¶
type SectionRenderer struct {
// contains filtered or unexported fields
}
SectionRenderer renders ReportSection to formatted terminal output.
func NewSectionRenderer ¶
func NewSectionRenderer(width int, verbose, noColor bool) *SectionRenderer
NewSectionRenderer creates a renderer with the given configuration.
func (*SectionRenderer) Render ¶
func (r *SectionRenderer) Render(section analyze.ReportSection) string
Render produces formatted output for a ReportSection.
func (*SectionRenderer) RenderCompact ¶
func (r *SectionRenderer) RenderCompact(section analyze.ReportSection) string
RenderCompact produces single-line output for narrow terminals. Format: "Title [████████░░] 8/10 Message".
func (*SectionRenderer) RenderSummary ¶
func (r *SectionRenderer) RenderSummary(summary *ExecutiveSummary) string
RenderSummary produces the executive summary output.
type UnifiedModel ¶
type UnifiedModel = analyze.UnifiedModel
UnifiedModel is a type alias for analyze.UnifiedModel so that existing code referencing renderer.UnifiedModel continues to compile without changes.