Documentation
¶
Overview ¶
Package format implements the output formats decolint can write a lint report in: human-readable text, a JSON object, GitHub Actions workflow command annotations, and a SARIF 2.1.0 log. Every format reports the configuration files that were linted alongside the issues found in them; see Report.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GitHubFormat ¶
type GitHubFormat struct{}
GitHubFormat prints the linted files as a collapsible log group, then one GitHub Actions workflow command (::error/::warning) per issue.
func (GitHubFormat) WriteReport ¶ added in v0.5.0
func (GitHubFormat) WriteReport(w io.Writer, report Report) error
WriteReport writes report to w as GitHub Actions workflow commands. Paths are written with "/" separators, which is what GitHub matches an annotation against.
The linted files go in a "::group::" block rather than in annotations of their own, so that the run log gains the context without a file that has no finding gaining an annotation.
type JSONFormat ¶
type JSONFormat struct{}
JSONFormat prints the report as a JSON object.
func (JSONFormat) WriteReport ¶ added in v0.5.0
func (JSONFormat) WriteReport(w io.Writer, report Report) error
WriteReport writes report to w as a JSON object with a "files" and an "issues" member, both always arrays. It marshals into an in-memory buffer first so that a failure never leaves partial JSON on w.
type Report ¶ added in v0.5.0
type Report struct {
// ConfigPath is the config file the run's settings came from, empty when none was found. Only
// [TextFormat] renders it; the machine-readable formats leave it out.
ConfigPath string
// Files are the configuration files that were linted, in the order they were visited. A file
// with no issue is listed too, so the report shows what was covered and not just what fired.
Files []File
// Issues are the findings, in the order they were reported.
Issues []linter.Issue
}
Report is the outcome of a lint run: the configuration files that were linted and the issues found in them.
type SARIFFormat ¶ added in v0.4.0
type SARIFFormat struct {
// Version is the tool version recorded in the run.
Version string
// Rules are the rules the run has enabled. They are declared in the log whether or not they
// produced a result, which is how a consumer tells a rule that ran clean from one that was
// switched off.
Rules []SARIFRule
}
SARIFFormat prints a SARIF 2.1.0 log, suitable for upload to GitHub Code Scanning.
func (SARIFFormat) WriteReport ¶ added in v0.5.0
func (f SARIFFormat) WriteReport(w io.Writer, report Report) error
WriteReport writes report to w as a SARIF 2.1.0 log with a single run. It marshals into an in-memory buffer first so that a failure never leaves partial output on w.
The run's rule catalog lists f.Rules, sorted by rule ID, so the log declares the rules the run covered and not just the ones that fired; a rule referenced by an issue but missing from f.Rules is listed with its ID alone. The linted files become the run's artifacts, which each result refers to by index. Paths are reported as URIs; see [artifactURIFor].
type SARIFRule ¶ added in v0.4.0
type SARIFRule struct {
ID string
Description string
Category string
// HelpURI is where the rule is documented in full.
HelpURI string
}
SARIFRule describes one rule for the SARIF rule catalog. It mirrors the linter.Rule fields the SARIF output needs, so this package does not depend on the rules package.
type TextFormat ¶
type TextFormat struct {
// Color, when true, decorates the report with ANSI escape sequences: the severity of an issue is
// colored, the position it is at stands out, and secondary details recede. Callers should enable
// it only for a destination that renders them, i.e. a terminal.
Color bool
}
TextFormat prints a header naming the config file and the linted files, then one line per issue, matching linter.Issue.String, and a summary.
func (TextFormat) WriteReport ¶ added in v0.5.0
func (f TextFormat) WriteReport(w io.Writer, report Report) error
WriteReport writes report to w.