Debian Codegraph @

README.md

raw symbols SCIP
1 # go-sarif
2 [![Go Report Card](https://goreportcard.com/badge/github.com/owenrumney/go-sarif)](https://goreportcard.com/report/github.com/owenrumney/go-sarif)
3 [![Github Release](https://img.shields.io/github/release/owenrumney/go-sarif.svg)](https://github.com/owenrumney/go-sarif/releases)
4
5 ## What?
6
7 SARIF is the Static Analysis Results Interchange Format, this project seeks to provide a simple interface to generate reports in the SARIF format.
8
9 ### Example report
10
11 This example is taken directly from the [Microsoft sarif pages](https://github.com/microsoft/sarif-tutorials/blob/master/docs/1-Introduction.md)
12
13 ```json
14 {
15 "version": "2.1.0",
16 "$schema": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json",
17 "runs": [
18 {
19 "tool": {
20 "driver": {
21 "name": "ESLint",
22 "informationUri": "https://eslint.org",
23 "rules": [
24 {
25 "id": "no-unused-vars",
26 "shortDescription": {
27 "text": "disallow unused variables"
28 },
29 "helpUri": "https://eslint.org/docs/rules/no-unused-vars",
30 "properties": {
31 "category": "Variables"
32 }
33 }
34 ]
35 }
36 },
37 "artifacts": [
38 {
39 "location": {
40 "uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js"
41 }
42 }
43 ],
44 "results": [
45 {
46 "level": "error",
47 "message": {
48 "text": "'x' is assigned a value but never used."
49 },
50 "locations": [
51 {
52 "physicalLocation": {
53 "artifactLocation": {
54 "uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js",
55 "index": 0
56 },
57 "region": {
58 "startLine": 1,
59 "startColumn": 5
60 }
61 }
62 }
63 ],
64 "ruleId": "no-unused-vars",
65 "ruleIndex": 0
66 }
67 ]
68 }
69 ]
70 }
71 ```
72
73 ## What prompted this?
74 One of the projects I like to contribute to is [tfsec](https://tfsec.dev) - this is a static analysis tool for Terraform which produces output in many formats. Generating SARIF reports is missing functionality and felt like it warranted being moved out to a project of its own.
75
76 ## More information about SARIF
77 For more information about SARIF, you can visit the [Oasis Open](https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=sarif) site.
78
79 ## Usage
80
81 Add an import to `go get github.com/owenrumney/go-sarif/sarif`
82 ### Parsing a Sarif report
83
84 There are a number of ways to load in the content of a sarif report.
85
86 #### Open
87
88 `sarif.Open` takes a file path and loads the sarif from that location. Returns a report and any corresponding error
89
90 #### FromBytes
91
92 `sarif.FromBytes` takes a slice of byte and returns a report and any corresponding error.
93
94 #### FromString
95
96 `sarif.FromString` takes a string of the sarif content and returns a report and any corresponding error.
97
98 ### Creating a new report
99
100 Creating a new Sarif report is done by passing the version, the only supported at the moment is `2.1.0`
101
102 for a detailed example check the example folder [example/main.go](example/main.go)
103