Documentation
¶
Overview ¶
Package sarif renders findings in the SARIF 2.1.0 format that code-scanning services (GitHub, GitLab, Azure DevOps) ingest. Only the properties a report populates are modelled, so the output stays deterministic and diffs cleanly.
Index ¶
- Constants
- func Level(severity string) string
- func Marshal(log *Log) ([]byte, error)
- func SortResults(results []Result)
- type ArtifactChange
- type ArtifactContent
- type ArtifactLocation
- type Driver
- type Fix
- type Location
- type Log
- type Message
- type PhysicalLocation
- type Properties
- type Region
- type Replacement
- type Result
- type Rule
- type RuleSet
- type Run
- type Tool
Constants ¶
const ( Version = "2.1.0" Schema = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json" )
Version is the SARIF version every log this package writes declares, and Schema the published schema of that version.
Variables ¶
This section is empty.
Functions ¶
func Level ¶
Level maps a validator severity (error, warning, info, hint) onto the SARIF levels error, warning and note.
func SortResults ¶
func SortResults(results []Result)
SortResults orders results by artifact, line, column and rule, so that a log of the same findings is the same document whatever order they were found in.
Types ¶
type ArtifactChange ¶
type ArtifactChange struct {
ArtifactLocation ArtifactLocation `json:"artifactLocation"`
Replacements []Replacement `json:"replacements"`
}
ArtifactChange is the replacements a fix makes in one artifact.
type ArtifactContent ¶
type ArtifactContent struct {
Text string `json:"text"`
}
ArtifactContent is text inserted by a replacement.
type ArtifactLocation ¶
type ArtifactLocation struct {
URI string `json:"uri"`
URIBaseID string `json:"uriBaseId,omitempty"`
}
ArtifactLocation names an artifact by URI, relative to the uriBaseId when one is given.
type Driver ¶
type Driver struct {
Name string `json:"name"`
InformationURI string `json:"informationUri,omitempty"`
Version string `json:"version,omitempty"`
Rules []Rule `json:"rules"`
}
Driver is the tool's primary component: its name, version and rules.
type Fix ¶
type Fix struct {
Description Message `json:"description"`
ArtifactChanges []ArtifactChange `json:"artifactChanges"`
}
Fix is one way to resolve a result: a set of edits to artifacts.
type Location ¶
type Location struct {
PhysicalLocation PhysicalLocation `json:"physicalLocation"`
}
Location places a result in an artifact.
func LocationAt ¶
LocationAt places a result at a 1-based line and column of an artifact; a column of 0 leaves the region a whole line. A whole-file finding, reported at line 0, is placed on the first line, as SARIF regions start at 1.
type Log ¶
type Log struct {
Schema string `json:"$schema"`
Version string `json:"version"`
Runs []Run `json:"runs"`
}
Log is the document root: one or more runs of a tool.
type PhysicalLocation ¶
type PhysicalLocation struct {
ArtifactLocation ArtifactLocation `json:"artifactLocation"`
Region *Region `json:"region,omitempty"`
}
PhysicalLocation is an artifact and a region within it.
type Properties ¶
type Properties struct {
// Suppressed is how many findings a baseline kept out of the results.
Suppressed int `json:"suppressed,omitempty"`
}
Properties is a run's property bag: what the run reports about itself beyond its results.
type Region ¶
type Region struct {
StartLine int `json:"startLine"`
StartColumn int `json:"startColumn,omitempty"`
EndLine int `json:"endLine,omitempty"`
EndColumn int `json:"endColumn,omitempty"`
}
Region is a 1-based span of an artifact's text. A zero EndLine or EndColumn is omitted, leaving the region to end where the format says a region without an end does.
type Replacement ¶
type Replacement struct {
DeletedRegion Region `json:"deletedRegion"`
InsertedContent *ArtifactContent `json:"insertedContent,omitempty"`
}
Replacement deletes a region and inserts content in its place; an insertion deletes an empty region.
type Result ¶
type Result struct {
RuleID string `json:"ruleId"`
RuleIndex int `json:"ruleIndex"`
Level string `json:"level"`
Message Message `json:"message"`
Locations []Location `json:"locations,omitempty"`
Fixes []Fix `json:"fixes,omitempty"`
}
Result is one finding.
type Rule ¶
type Rule struct {
ID string `json:"id"`
ShortDescription Message `json:"shortDescription"`
HelpURI string `json:"helpUri,omitempty"`
Properties *RuleSet `json:"properties,omitempty"`
}
Rule describes one kind of finding, keyed by the id its results carry.
type RuleSet ¶
type RuleSet struct {
Tags []string `json:"tags,omitempty"`
}
RuleSet carries a rule's property bag: the tags a consumer filters on.
type Run ¶
type Run struct {
Tool Tool `json:"tool"`
Results []Result `json:"results"`
// ColumnKind is what the columns count: "utf16CodeUnits" (the default
// readers assume) or "unicodeCodePoints".
ColumnKind string `json:"columnKind,omitempty"`
Properties *Properties `json:"properties,omitempty"`
}
Run is one invocation of one tool and the results it produced.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sariftest validates SARIF documents against the vendored SARIF 2.1.0 schema, so a writer's tests can prove its output is what a code-scanning service reads.
|
Package sariftest validates SARIF documents against the vendored SARIF 2.1.0 schema, so a writer's tests can prove its output is what a code-scanning service reads. |