Skip to content

Commit

Permalink
chore: Update to owenrumney/go-sarif/v2 (#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
oWretch authored Sep 2, 2024
1 parent c7a4725 commit 4bda000
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 58 deletions.
22 changes: 12 additions & 10 deletions formatter/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"

"github.com/hashicorp/hcl/v2"
"github.com/owenrumney/go-sarif/sarif"
"github.com/owenrumney/go-sarif/v2/sarif"
sdk "github.com/terraform-linters/tflint-plugin-sdk/tflint"
"github.com/terraform-linters/tflint/tflint"
)
Expand All @@ -17,15 +17,17 @@ func (f *Formatter) sarifPrint(issues tflint.Issues, appErr error) {
panic(initErr)
}

run := sarif.NewRun("tflint", "https://github.com/terraform-linters/tflint")
run := sarif.NewRunWithInformationURI("tflint", "https://github.com/terraform-linters/tflint")

version := tflint.Version.String()
run.Tool.Driver.Version = &version

report.AddRun(run)

for _, issue := range issues {
rule := run.AddRule(issue.Rule.Name()).WithHelpURI(issue.Rule.Link()).WithDescription("")
rule := run.AddRule(issue.Rule.Name()).
WithHelpURI(issue.Rule.Link()).
WithDescription("")

var level string
switch issue.Rule.Severity() {
Expand Down Expand Up @@ -55,16 +57,16 @@ func (f *Formatter) sarifPrint(issues tflint.Issues, appErr error) {
}
}

result := run.AddResult(rule.ID).
result := run.CreateResultForRule(rule.ID).
WithLevel(level).
WithMessage(sarif.NewTextMessage(issue.Message))

if location != nil {
result.WithLocation(sarif.NewLocationWithPhysicalLocation(location))
result.AddLocation(sarif.NewLocationWithPhysicalLocation(location))
}
}

errRun := sarif.NewRun("tflint-errors", "https://github.com/terraform-linters/tflint")
errRun := sarif.NewRunWithInformationURI("tflint-errors", "https://github.com/terraform-linters/tflint")
errRun.Tool.Driver.Version = &version

report.AddRun(errRun)
Expand Down Expand Up @@ -105,15 +107,15 @@ func (f *Formatter) sarifAddErrors(errRun *sarif.Run, err error) {
WithEndColumn(diag.Subject.End.Column),
)

errRun.AddResult(diag.Summary).
errRun.CreateResultForRule(diag.Summary).
WithLevel(fromHclSeverity(diag.Severity)).
WithLocation(sarif.NewLocationWithPhysicalLocation(location)).
WithMessage(sarif.NewTextMessage(diag.Detail))
WithMessage(sarif.NewTextMessage(diag.Detail)).
AddLocation(sarif.NewLocationWithPhysicalLocation(location))
}
return
}

errRun.AddResult("application_error").
errRun.CreateResultForRule("application_error").
WithLevel("error").
WithMessage(sarif.NewTextMessage(err.Error()))
}
Loading

0 comments on commit 4bda000

Please sign in to comment.