sarif

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Level(severity string) string

Level maps a validator severity (error, warning, info, hint) onto the SARIF levels error, warning and note.

func Marshal

func Marshal(log *Log) ([]byte, error)

Marshal renders the log as indented JSON ending in a newline.

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

func LocationAt(uri string, line, column int) []Location

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.

func NewLog

func NewLog(driver Driver) *Log

NewLog returns a log of one run by the named tool, with no results yet.

type Message

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

Message is a plain-text message.

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.

type Tool

type Tool struct {
	Driver Driver `json:"driver"`
}

Tool names the analysis tool a run was made by.

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.

Jump to

Keyboard shortcuts

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