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
This commit is contained in:
bplaxco authored and GitHub committed 2025-02-24 08:28:06 -06:00
1 parent 59fdd904af
commit f6a7439306
4 files changed
+11 -6

No files matched your search

+1 -1
View File
@@ -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)
}
+8 -3
View File
@@ -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
}
+1 -1
View File
@@ -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)
}
}
+1 -1
View File
@@ -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