Skip to content

Commit

Permalink
sort secret findings
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Sep 6, 2022
1 parent 21ced14 commit 6534382
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/fanal/secret/scanner.go
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"os"
"regexp"
"sort"
"strings"
"sync"

Expand Down Expand Up @@ -337,7 +338,7 @@ type Match struct {
Location Location
}

func (s Scanner) Scan(args ScanArgs) types.Secret {
func (s *Scanner) Scan(args ScanArgs) types.Secret {
// Global allowed paths
if s.AllowPath(args.FilePath) {
return types.Secret{
Expand Down Expand Up @@ -401,6 +402,13 @@ func (s Scanner) Scan(args ScanArgs) types.Secret {
return types.Secret{}
}

sort.Slice(findings, func(i, j int) bool {
if findings[i].RuleID != findings[j].RuleID {
return findings[i].RuleID != findings[j].RuleID
}
return findings[i].Match < findings[j].Match
})

return types.Secret{
FilePath: args.FilePath,
Findings: findings,
Expand Down

0 comments on commit 6534382

Please sign in to comment.