output

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 7 Imported by: 0

README

Output Formatters

Overview

This package provides output formatters for structurelint violations.

Available Formatters

  • TextFormatter: Human-readable text output (default)
  • JSONFormatter: Machine-readable JSON format for CI/CD integration
  • JUnitFormatter: JUnit XML format for Jenkins, GitHub Actions, etc.

Usage

formatter, err := output.GetFormatter("json")
if err != nil {
    return err
}

formatted, err := formatter.Format(violations)
if err != nil {
    return err
}

fmt.Print(formatted)

Supported Formats

  • text - Plain text output with file:message format
  • json - JSON with version, timestamp, and structured violations
  • junit - JUnit XML grouped by rule name

Documentation

Overview

@structurelint:ignore test-adjacency Output formatters are integration-tested through CLI

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter interface {
	Format(violations []rules.Violation) (string, error)
}

Formatter defines the interface for output formatters

func GetFormatter

func GetFormatter(format string, version string) (Formatter, error)

GetFormatter returns a formatter based on the format name

type JSONFormatter

type JSONFormatter struct {
	Version string
}

JSONFormatter formats violations as JSON

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(violations []rules.Violation) (string, error)

Format formats violations as JSON

type JSONOutput

type JSONOutput struct {
	Version    string          `json:"version"`
	Timestamp  string          `json:"timestamp"`
	Violations int             `json:"violations"`
	Results    []JSONViolation `json:"results"`
}

JSONOutput represents the JSON output structure

type JSONViolation

type JSONViolation struct {
	Rule    string `json:"rule"`
	Path    string `json:"path"`
	Message string `json:"message"`
}

JSONViolation represents a single violation in JSON format

type JUnitFailure

type JUnitFailure struct {
	Message string `xml:"message,attr"`
	Type    string `xml:"type,attr"`
	Content string `xml:",chardata"`
}

JUnitFailure represents a test failure

type JUnitFormatter

type JUnitFormatter struct{}

JUnitFormatter formats violations as JUnit XML

func (*JUnitFormatter) Format

func (f *JUnitFormatter) Format(violations []rules.Violation) (string, error)

Format formats violations as JUnit XML

type JUnitTestCase

type JUnitTestCase struct {
	Name      string        `xml:"name,attr"`
	Classname string        `xml:"classname,attr"`
	Time      string        `xml:"time,attr"`
	Failure   *JUnitFailure `xml:"failure,omitempty"`
}

JUnitTestCase represents a test case

type JUnitTestSuite

type JUnitTestSuite struct {
	Name      string          `xml:"name,attr"`
	Tests     int             `xml:"tests,attr"`
	Failures  int             `xml:"failures,attr"`
	Errors    int             `xml:"errors,attr"`
	Time      string          `xml:"time,attr"`
	Timestamp string          `xml:"timestamp,attr"`
	TestCases []JUnitTestCase `xml:"testcase"`
}

JUnitTestSuite represents a test suite

type JUnitTestSuites

type JUnitTestSuites struct {
	XMLName    xml.Name         `xml:"testsuites"`
	XMLNS      string           `xml:"xmlns,attr,omitempty"`
	Name       string           `xml:"name,attr"`
	Tests      int              `xml:"tests,attr"`
	Failures   int              `xml:"failures,attr"`
	Errors     int              `xml:"errors,attr"`
	Time       string           `xml:"time,attr"`
	TestSuites []JUnitTestSuite `xml:"testsuite"`
}

JUnitTestSuites represents the root element of JUnit XML

type TextFormatter

type TextFormatter struct{}

TextFormatter formats violations as plain text

func (*TextFormatter) Format

func (f *TextFormatter) Format(violations []rules.Violation) (string, error)

Format formats violations as plain text

Jump to

Keyboard shortcuts

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