From f6a7439306891efa07becf0bab87421ed1b6616a Mon Sep 17 00:00:00 2001 From: bplaxco Date: Mon, 24 Feb 2025 09:28:06 -0500 Subject: [PATCH] Make AddFindings public (#1767) - Rename d.addFindings -> d.AddFindings - Add d.Findings() To allow other tools using d.Detect() to leverage the code in AddFindings --- detect/baseline_test.go | 2 +- detect/detect.go | 11 ++++++++--- detect/directory.go | 2 +- detect/git.go | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/detect/baseline_test.go b/detect/baseline_test.go index 6eca4e65..1d6e59b2 100644 --- a/detect/baseline_test.go +++ b/detect/baseline_test.go @@ -133,7 +133,7 @@ func TestIgnoreIssuesInBaseline(t *testing.T) { require.NoError(t, err) d.baseline = test.baseline for _, finding := range test.findings { - d.addFinding(finding) + d.AddFinding(finding) } assert.Len(t, d.findings, test.expectCount) } diff --git a/detect/detect.go b/detect/detect.go index f2990d92..8bc418f5 100644 --- a/detect/detect.go +++ b/detect/detect.go @@ -568,8 +568,8 @@ func allTrue(bools []bool) bool { return allMatch } -// addFinding synchronously adds a finding to the findings slice -func (d *Detector) addFinding(finding report.Finding) { +// AddFinding synchronously adds a finding to the findings slice +func (d *Detector) AddFinding(finding report.Finding) { globalFingerprint := fmt.Sprintf("%s:%s:%d", finding.File, finding.RuleID, finding.StartLine) if finding.Commit != "" { finding.Fingerprint = fmt.Sprintf("%s:%s:%s:%d", finding.Commit, finding.File, finding.RuleID, finding.StartLine) @@ -609,7 +609,12 @@ func (d *Detector) addFinding(finding report.Finding) { d.findingMutex.Unlock() } -// addCommit synchronously adds a commit to the commit slice +// Findings returns the findings added to the detector +func (d *Detector) Findings() []report.Finding { + return d.findings +} + +// AddCommit synchronously adds a commit to the commit slice func (d *Detector) addCommit(commit string) { d.commitMap[commit] = true } diff --git a/detect/directory.go b/detect/directory.go index cd9d9f42..7beb5e6f 100644 --- a/detect/directory.go +++ b/detect/directory.go @@ -102,7 +102,7 @@ func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Findin // need to add 1 since line counting starts at 1 finding.StartLine += (totalLines - linesInChunk) + 1 finding.EndLine += (totalLines - linesInChunk) + 1 - d.addFinding(finding) + d.AddFinding(finding) } } diff --git a/detect/git.go b/detect/git.go index b1347de1..89ae1400 100644 --- a/detect/git.go +++ b/detect/git.go @@ -62,7 +62,7 @@ func (d *Detector) DetectGit(cmd *sources.GitCmd, remote *RemoteInfo) ([]report. } for _, finding := range d.Detect(fragment) { - d.addFinding(augmentGitFinding(remote, finding, textFragment, gitdiffFile)) + d.AddFinding(augmentGitFinding(remote, finding, textFragment, gitdiffFile)) } } return nil