reporter

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package reporter provides diagnostic and diff reporting functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiffReporter

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

DiffReporter formats results as unified diffs in GitHub style.

func NewDiffReporter

func NewDiffReporter(opts Options) *DiffReporter

NewDiffReporter creates a new diff reporter.

func (*DiffReporter) Report

func (r *DiffReporter) Report(_ context.Context, result *runner.Result) (int, error)

Report implements Reporter.

type Format

type Format string

Format represents an output format.

const (
	FormatText    Format = "text"
	FormatTable   Format = "table"
	FormatJSON    Format = "json"
	FormatSARIF   Format = "sarif"
	FormatDiff    Format = "diff"
	FormatSummary Format = "summary"
)

Output formats supported by the reporter.

func ParseFormat

func ParseFormat(formatStr string) (Format, error)

ParseFormat parses a format string, returning an error for unknown formats.

func (Format) IsValid

func (f Format) IsValid() bool

IsValid returns true if the format is a known valid format.

func (Format) String

func (f Format) String() string

String returns the string representation of the format.

type JSONDiagnostic

type JSONDiagnostic struct {
	RuleID      string    `json:"ruleId"`
	RuleName    string    `json:"ruleName"`
	Severity    string    `json:"severity"`
	Message     string    `json:"message"`
	StartLine   int       `json:"startLine"`
	StartColumn int       `json:"startColumn"`
	EndLine     int       `json:"endLine"`
	EndColumn   int       `json:"endColumn"`
	Suggestion  string    `json:"suggestion,omitempty"`
	Fixable     bool      `json:"fixable"`
	Fixes       []JSONFix `json:"fixes,omitempty"`
}

JSONDiagnostic represents a single diagnostic.

type JSONFileResult

type JSONFileResult struct {
	Path        string           `json:"path"`
	Diagnostics []JSONDiagnostic `json:"diagnostics"`
	Modified    bool             `json:"modified,omitempty"`
	Error       string           `json:"error,omitempty"`
}

JSONFileResult represents a single file's results.

type JSONFix

type JSONFix struct {
	StartOffset int    `json:"startOffset"`
	EndOffset   int    `json:"endOffset"`
	NewText     string `json:"newText"`
}

JSONFix represents a proposed fix.

type JSONOutput

type JSONOutput struct {
	Version string           `json:"version"`
	Files   []JSONFileResult `json:"files"`
	Summary JSONSummary      `json:"summary"`
}

JSONOutput is the top-level JSON structure.

type JSONReporter

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

JSONReporter formats results as JSON.

func NewJSONReporter

func NewJSONReporter(opts Options) *JSONReporter

NewJSONReporter creates a new JSON reporter.

func (*JSONReporter) Report

func (r *JSONReporter) Report(_ context.Context, result *runner.Result) (int, error)

Report implements Reporter.

type JSONSummary

type JSONSummary struct {
	FilesChecked    int            `json:"filesChecked"`
	FilesWithIssues int            `json:"filesWithIssues"`
	FilesModified   int            `json:"filesModified"`
	FilesErrored    int            `json:"filesErrored"`
	TotalIssues     int            `json:"totalIssues"`
	BySeverity      map[string]int `json:"bySeverity"`
}

JSONSummary contains aggregate statistics.

type Options

type Options struct {
	// Writer is the destination for output (typically os.Stdout).
	Writer io.Writer

	// ErrorWriter is the destination for errors (typically os.Stderr).
	ErrorWriter io.Writer

	// Format specifies the output format.
	Format Format

	// Color controls colorized output.
	// Values: "auto" (default), "always", "never"
	Color string

	// ShowContext includes source line context in diagnostics.
	ShowContext bool

	// ShowSummary displays aggregate statistics after results.
	ShowSummary bool

	// GroupByFile groups diagnostics by file (default: true for text format).
	GroupByFile bool

	// Compact uses compact/minified output where applicable.
	Compact bool

	// PerFile outputs a separate report for each file (table format only).
	PerFile bool

	// RuleFormat controls how rule identifiers appear in output.
	RuleFormat config.RuleFormat

	// SummaryOrder controls the order of tables in summary output.
	SummaryOrder config.SummaryOrder

	// WorkingDir is the directory to make paths relative to.
	// If empty, paths are kept as-is (typically absolute).
	WorkingDir string
}

Options configures reporter behavior.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns Options with sensible defaults.

type Renderer

type Renderer interface {
	// Render writes the formatted report to the configured output.
	Render(ctx context.Context, report *analysis.Report) error
}

Renderer formats an analysis.Report for output. Renderers are stateless and only handle presentation logic.

type Reporter

type Reporter interface {
	// Report writes formatted output for the given result.
	// It returns the number of issues reported and any write errors.
	Report(ctx context.Context, result *runner.Result) (int, error)
}

Reporter formats and writes lint results.

func New

func New(opts Options) (Reporter, error)

New creates a Reporter for the specified options.

type SARIFArtifactChange

type SARIFArtifactChange struct {
	ArtifactLocation SARIFArtifactLocation `json:"artifactLocation"`
	Replacements     []SARIFReplacement    `json:"replacements"`
}

SARIFArtifactChange describes changes to a file.

type SARIFArtifactLocation

type SARIFArtifactLocation struct {
	URI string `json:"uri"`
}

SARIFArtifactLocation contains the file URI.

type SARIFDriver

type SARIFDriver struct {
	Name           string      `json:"name"`
	Version        string      `json:"version"`
	InformationURI string      `json:"informationUri"`
	Rules          []SARIFRule `json:"rules"`
}

SARIFDriver contains tool metadata and rules.

type SARIFFix

type SARIFFix struct {
	Description     SARIFMessage          `json:"description"`
	ArtifactChanges []SARIFArtifactChange `json:"artifactChanges"`
}

SARIFFix represents a proposed fix.

type SARIFInsertedContent

type SARIFInsertedContent struct {
	Text string `json:"text"`
}

SARIFInsertedContent contains the replacement text.

type SARIFLocation

type SARIFLocation struct {
	PhysicalLocation SARIFPhysicalLocation `json:"physicalLocation"`
}

SARIFLocation describes a code location.

type SARIFMessage

type SARIFMessage struct {
	Text string `json:"text"`
}

SARIFMessage contains the result message.

type SARIFMultiformatText

type SARIFMultiformatText struct {
	Text string `json:"text"`
}

SARIFMultiformatText contains text in multiple formats.

type SARIFOutput

type SARIFOutput struct {
	Schema  string     `json:"$schema"`
	Version string     `json:"version"`
	Runs    []SARIFRun `json:"runs"`
}

SARIFOutput represents the root SARIF document.

type SARIFPhysicalLocation

type SARIFPhysicalLocation struct {
	ArtifactLocation SARIFArtifactLocation `json:"artifactLocation"`
	Region           SARIFRegion           `json:"region"`
}

SARIFPhysicalLocation contains file path and region.

type SARIFRegion

type SARIFRegion struct {
	StartLine   int `json:"startLine"`
	StartColumn int `json:"startColumn,omitempty"`
	EndLine     int `json:"endLine,omitempty"`
	EndColumn   int `json:"endColumn,omitempty"`
}

SARIFRegion describes the affected text region.

type SARIFReplacement

type SARIFReplacement struct {
	DeletedRegion   SARIFRegion           `json:"deletedRegion"`
	InsertedContent *SARIFInsertedContent `json:"insertedContent,omitempty"`
}

SARIFReplacement describes a text replacement.

type SARIFReporter

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

SARIFReporter formats results as SARIF.

func NewSARIFReporter

func NewSARIFReporter(opts Options) *SARIFReporter

NewSARIFReporter creates a new SARIF reporter.

func (*SARIFReporter) Report

func (r *SARIFReporter) Report(_ context.Context, result *runner.Result) (int, error)

Report implements Reporter.

type SARIFResult

type SARIFResult struct {
	RuleID    string          `json:"ruleId"`
	Level     string          `json:"level"`
	Message   SARIFMessage    `json:"message"`
	Locations []SARIFLocation `json:"locations"`
	Fixes     []SARIFFix      `json:"fixes,omitempty"`
}

SARIFResult represents a single diagnostic result.

type SARIFRule

type SARIFRule struct {
	ID               string               `json:"id"`
	Name             string               `json:"name,omitempty"`
	ShortDescription SARIFMultiformatText `json:"shortDescription,omitempty"`
	DefaultConfig    *SARIFRuleConfig     `json:"defaultConfiguration,omitempty"`
	Properties       map[string]any       `json:"properties,omitempty"`
}

SARIFRule describes a rule (linter check).

type SARIFRuleConfig

type SARIFRuleConfig struct {
	Level string `json:"level"`
}

SARIFRuleConfig contains rule configuration.

type SARIFRun

type SARIFRun struct {
	Tool    SARIFTool     `json:"tool"`
	Results []SARIFResult `json:"results"`
}

SARIFRun represents a single analysis run.

type SARIFTool

type SARIFTool struct {
	Driver SARIFDriver `json:"driver"`
}

SARIFTool describes the analysis tool.

type SummaryRenderer

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

SummaryRenderer formats results as aggregated summary tables.

func NewSummaryRenderer

func NewSummaryRenderer(opts Options) *SummaryRenderer

NewSummaryRenderer creates a new summary renderer.

func (*SummaryRenderer) Render

func (r *SummaryRenderer) Render(_ context.Context, report *analysis.Report) error

Render implements Renderer.

type TableReporter

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

TableReporter formats results as a styled table with color-coded rows.

func NewTableReporter

func NewTableReporter(opts Options) *TableReporter

NewTableReporter creates a new table reporter.

func (*TableReporter) Report

func (r *TableReporter) Report(_ context.Context, result *runner.Result) (int, error)

Report implements Reporter.

type TextReporter

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

TextReporter formats results as styled terminal output.

func NewTextReporter

func NewTextReporter(opts Options) *TextReporter

NewTextReporter creates a new text reporter.

func (*TextReporter) Report

func (r *TextReporter) Report(ctx context.Context, result *runner.Result) (int, error)

Report implements Reporter.

Jump to

Keyboard shortcuts

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