Skip to content

Commit

Permalink
The compact output format should include a summary #1364 (#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
anaypurohit0907 authored Jan 27, 2025
1 parent b29ad44 commit 856bf50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions pkg/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,22 @@ func (tr CompactReporter) Publish(_ context.Context, r report.Report) error {
for _, violation := range r.Violations {
table.Append([]string{violation.Location.String(), violation.Description})
}
// plurals
pluralScanned := ""
if r.Summary.FilesScanned > 1 || r.Summary.FilesScanned == 0 {
pluralScanned = "s"
}
pluralViolations := ""

Check failure on line 305 in pkg/reporter/reporter.go

View workflow job for this annotation

GitHub Actions / Matrix (ubuntu-latest, linux, true)

assignments should only be cuddled with other assignments (wsl)
if r.Summary.NumViolations > 1 || r.Summary.NumViolations == 0 {

Check failure on line 306 in pkg/reporter/reporter.go

View workflow job for this annotation

GitHub Actions / Matrix (ubuntu-latest, linux, true)

only one cuddle assignment allowed before if statement (wsl)
pluralViolations = "s"
}

summary := fmt.Sprintf("%d file%s linted , %d violation%s found.",
r.Summary.FilesScanned, pluralScanned,
r.Summary.NumViolations, pluralViolations)
// rendering the table
table.Render()

_, err := fmt.Fprintln(tr.out, strings.TrimSuffix(sb.String(), " "))

_, err := fmt.Fprintln(tr.out, strings.TrimSuffix(sb.String(), ""), summary)

Check failure on line 315 in pkg/reporter/reporter.go

View workflow job for this annotation

GitHub Actions / Matrix (ubuntu-latest, linux, true)

assignments should only be cuddled with other assignments (wsl)
return err

Check failure on line 316 in pkg/reporter/reporter.go

View workflow job for this annotation

GitHub Actions / Matrix (ubuntu-latest, linux, true)

return with no blank line before (nlreturn)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/reporter/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ func TestCompactReporterPublish(t *testing.T) {
| a.rego:1:1 | Rego must not break the law! |
| b.rego:22:18 | Questionable decision found |
+--------------+------------------------------+
3 files linted , 2 violations found.
`

if buf.String() != expect {
t.Errorf("expected %s, got %s", expect, buf.String())
}
Expand Down

0 comments on commit 856bf50

Please sign in to comment.