output

package
v0.33.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MarshalCLI = marshalerFunc(func(data analysis.Diagnostics) ([]byte, error) {
	var buf bytes.Buffer
	for name := range data {
		for _, d := range data[name] {
			switch d.Severity {
			case analysis.Error:
				buf.WriteString(color.RedString("error: "))
			case analysis.Warning:
				buf.WriteString(color.YellowString("warning: "))
			case analysis.Recommendation:
				buf.WriteString(color.CyanString("recommendation: "))
			case analysis.OK:
				buf.WriteString(color.GreenString("ok: "))
			case analysis.SuspectedProblem:
				buf.WriteString(color.YellowString("suspected: "))
			}

			if d.Context != "" {
				buf.WriteString(d.Context + ": ")
			}

			buf.WriteString(d.Title)
			if len(d.Detail) > 0 {
				buf.WriteRune('\n')
				buf.WriteString(color.BlueString("detail: "))
				buf.WriteString(d.Detail)
			}
			buf.WriteRune('\n')
		}
	}
	return buf.Bytes(), nil
})

MarshalCLI is a Marshaler that returns the diagnostics data in a human-readable format, for CLI usage.

View Source
var MarshalGHA = marshalerFunc(func(data analysis.Diagnostics) ([]byte, error) {
	var buf bytes.Buffer
	for name := range data {
		for _, d := range data[name] {
			var readableSeverity string
			switch d.Severity {
			case analysis.Error:
				buf.WriteString("::error ")
				readableSeverity = "Error"
			case analysis.Warning, analysis.SuspectedProblem:
				buf.WriteString("::warning ")
				readableSeverity = "Warning"
			case analysis.Recommendation:
				buf.WriteString("::notice ")
				readableSeverity = "Recommendation"
			case analysis.OK:
				buf.WriteString("::debug::")
				readableSeverity = "OK"
			}

			ghaTitleFallback := "plugin-validator: " + readableSeverity

			ghaTitle := ghaTitleFallback
			var ghaMessage string

			diagnosticsTitle := d.Title
			if d.Context != "" {

				diagnosticsTitle = d.Context + ": " + diagnosticsTitle
			}
			if diagnosticsTitle != "" {
				ghaTitle += ": " + diagnosticsTitle
			}

			if d.Detail != "" {

				ghaMessage = d.Detail
			} else {

				ghaMessage = diagnosticsTitle
				ghaTitle = ghaTitleFallback
			}
			buf.WriteString("title=")
			buf.WriteString(ghaEscape(ghaTitle))
			buf.WriteString("::")
			buf.WriteString(ghaEscape(ghaMessage))
			buf.WriteRune('\n')
		}
	}
	return buf.Bytes(), nil
})

MarshalGHA is a Marshaler that returns the diagnostics data in GitHub Actions workflow commands format. See GitHub Actions docs for more information: https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands#setting-a-notice-message

Functions

func ExitCode

func ExitCode(strict bool, diags analysis.Diagnostics) int

ExitCode returns the exit code of the CLI program. It returns: 1 if there's an error; 1 if there's a warning AND strict is true; 0 in all other cases.

Types

type Marshaler

type Marshaler interface {
	// Marshal encodes the diagnostics data in the format implemented by the marshaler.
	Marshal(data analysis.Diagnostics) ([]byte, error)
}

Marshaler is an interface for encoding the analysis results into bytes. Each implementation outputs the analysis results in a different format.

func NewJSONMarshaler

func NewJSONMarshaler(id string, version string) Marshaler

NewJSONMarshaler returns a new Marshaler that outputs the diagnostics data in JSON format. This marshaler requires additional plugin id and plugin version arguments.

Jump to

Keyboard shortcuts

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