Preserve missing-tool findings in CLI reports
This commit is contained in:
parent
3bfd2a46bc
commit
47c0f56863
2 changed files with 32 additions and 32 deletions
|
|
@ -91,7 +91,6 @@ func newRunCommand(commandName string, summary string, defaults lintpkg.RunInput
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
report = stripMissingToolFindings(report)
|
||||
|
||||
if err := writeReport(command.OutOrStdout(), input.Output, report); err != nil {
|
||||
return err
|
||||
|
|
@ -424,30 +423,6 @@ func writeIndentedJSON(writer io.Writer, value any) error {
|
|||
return encoder.Encode(value)
|
||||
}
|
||||
|
||||
func stripMissingToolFindings(report lintpkg.Report) lintpkg.Report {
|
||||
if len(report.Findings) == 0 {
|
||||
return report
|
||||
}
|
||||
passed := report.Summary.Passed
|
||||
|
||||
filtered := make([]lintpkg.Finding, 0, len(report.Findings))
|
||||
for _, finding := range report.Findings {
|
||||
if finding.Code == "missing-tool" {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, finding)
|
||||
}
|
||||
|
||||
if len(filtered) == len(report.Findings) {
|
||||
return report
|
||||
}
|
||||
|
||||
report.Findings = filtered
|
||||
report.Summary = lintpkg.Summarise(filtered)
|
||||
report.Summary.Passed = passed
|
||||
return report
|
||||
}
|
||||
|
||||
func writeCatalogSummary(writer io.Writer, findings []lintpkg.Finding) {
|
||||
summary := lintpkg.Summarise(findings)
|
||||
fmt.Fprintf(writer, "\n%d finding(s)", summary.Total)
|
||||
|
|
|
|||
|
|
@ -44,9 +44,24 @@ func Run() {
|
|||
|
||||
var report lintpkg.Report
|
||||
require.NoError(t, json.Unmarshal([]byte(stdout), &report))
|
||||
require.Len(t, report.Findings, 1)
|
||||
assert.Equal(t, "go-cor-003", report.Findings[0].Code)
|
||||
assert.Equal(t, 1, report.Summary.Total)
|
||||
require.NotEmpty(t, report.Findings)
|
||||
assert.GreaterOrEqual(t, report.Summary.Total, 2)
|
||||
assert.Greater(t, report.Summary.Info, 0)
|
||||
assert.Contains(t, report.Summary.BySeverity, "info")
|
||||
assert.Contains(t, report.Summary.BySeverity, "warning")
|
||||
|
||||
var hasCatalogFinding bool
|
||||
var hasMissingToolFinding bool
|
||||
for _, finding := range report.Findings {
|
||||
switch finding.Code {
|
||||
case "go-cor-003":
|
||||
hasCatalogFinding = true
|
||||
case "missing-tool":
|
||||
hasMissingToolFinding = true
|
||||
}
|
||||
}
|
||||
assert.True(t, hasCatalogFinding)
|
||||
assert.True(t, hasMissingToolFinding)
|
||||
assert.False(t, report.Summary.Passed)
|
||||
}
|
||||
|
||||
|
|
@ -74,8 +89,13 @@ func helper() error { return nil }
|
|||
|
||||
var report lintpkg.Report
|
||||
require.NoError(t, json.Unmarshal([]byte(stdout), &report))
|
||||
assert.Empty(t, report.Findings)
|
||||
assert.Equal(t, 0, report.Summary.Total)
|
||||
require.NotEmpty(t, report.Findings)
|
||||
assert.Equal(t, 6, report.Summary.Total)
|
||||
assert.Equal(t, 6, report.Summary.Info)
|
||||
for _, finding := range report.Findings {
|
||||
assert.Equal(t, "missing-tool", finding.Code)
|
||||
assert.Equal(t, "info", finding.Severity)
|
||||
}
|
||||
assert.True(t, report.Summary.Passed)
|
||||
}
|
||||
|
||||
|
|
@ -115,8 +135,13 @@ schedules:
|
|||
|
||||
var report lintpkg.Report
|
||||
require.NoError(t, json.Unmarshal([]byte(stdout), &report))
|
||||
assert.Empty(t, report.Findings)
|
||||
assert.Equal(t, 0, report.Summary.Total)
|
||||
require.NotEmpty(t, report.Findings)
|
||||
assert.Equal(t, 6, report.Summary.Total)
|
||||
assert.Equal(t, 6, report.Summary.Info)
|
||||
for _, finding := range report.Findings {
|
||||
assert.Equal(t, "missing-tool", finding.Code)
|
||||
assert.Equal(t, "info", finding.Severity)
|
||||
}
|
||||
assert.True(t, report.Summary.Passed)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue