Skip to content

Commit 3a9a6ad

Browse files
authored
Sarif provide Snippet with Issue.Code
* Provide Snippet with Issue.Code * Fix documentation
1 parent 1325319 commit 3a9a6ad

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

report/sarif/builder.go

+13
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ func NewRegion(startLine int, endLine int, startColumn int, endColumn int, sourc
5858
}
5959
}
6060

61+
//WithSnippet defines the Snippet for the current Region
62+
func (r *Region) WithSnippet(snippet *ArtifactContent) *Region {
63+
r.Snippet = snippet
64+
return r
65+
}
66+
67+
//NewArtifactContent instantiate an ArtifactContent
68+
func NewArtifactContent(text string) *ArtifactContent {
69+
return &ArtifactContent{
70+
Text: text,
71+
}
72+
}
73+
6174
//NewTool instantiate a Tool
6275
func NewTool(driver *ToolComponent) *Tool {
6376
return &Tool{

report/sarif/formatter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ func parseSarifRegion(issue *gosec.Issue) (*Region, error) {
172172
return nil, err
173173
}
174174
}
175-
176175
col, err := strconv.Atoi(issue.Col)
177176
if err != nil {
178177
return nil, err
179178
}
180-
return NewRegion(startLine, endLine, col, col, "go"), nil
179+
snippet := NewArtifactContent(issue.Code)
180+
return NewRegion(startLine, endLine, col, col, "go").WithSnippet(snippet), nil
181181
}
182182

183183
func getSarifLevel(s string) Level {

0 commit comments

Comments
 (0)