Skip to content

Commit 1cabafc

Browse files
authored
feat: use gosec severities (golangci#4470)
1 parent d06296e commit 1cabafc

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/golinters/gosec.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoS
9797

9898
issues := make([]goanalysis.Issue, 0, len(secIssues))
9999
for _, i := range secIssues {
100-
text := fmt.Sprintf("%s: %s", i.RuleID, i.What) // TODO: use severity and confidence
100+
text := fmt.Sprintf("%s: %s", i.RuleID, i.What)
101101

102102
var r *result.Range
103103

@@ -118,6 +118,7 @@ func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoS
118118
}
119119

120120
issues = append(issues, goanalysis.NewIssue(&result.Issue{
121+
Severity: convertScoreToString(i.Severity),
121122
Pos: token.Position{
122123
Filename: i.File,
123124
Line: line,
@@ -149,6 +150,19 @@ func toGosecConfig(settings *config.GoSecSettings) gosec.Config {
149150
return conf
150151
}
151152

153+
func convertScoreToString(score issue.Score) string {
154+
switch score {
155+
case issue.Low:
156+
return "low"
157+
case issue.Medium:
158+
return "medium"
159+
case issue.High:
160+
return "high"
161+
default:
162+
return ""
163+
}
164+
}
165+
152166
// based on https://github.com/securego/gosec/blob/47bfd4eb6fc7395940933388550b547538b4c946/config.go#L52-L62
153167
func convertGosecGlobals(globalOptionFromConfig any, conf gosec.Config) {
154168
globalOptionMap, ok := globalOptionFromConfig.(map[string]any)

0 commit comments

Comments
 (0)