Skip to content

Commit 209c443

Browse files
author
Hugo DELVAL
committed
Fix report Table formatting
1 parent 860b081 commit 209c443

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

spamc.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,23 @@ type Report struct {
349349

350350
// String formats the reports like SpamAssassin.
351351
func (r Report) String() string {
352-
table := " pts rule name description\n"
353-
table += "---- ---------------------- --------------------------------------------------\n"
352+
table := " pts rule name description\n"
353+
table += "---- -------------------------------- --------------------------------------------------\n"
354354

355355
for _, t := range r.Table {
356356
leadingSpace := ""
357-
if t.Points > 0 {
357+
// Only checking if t.Points is >=0 is not enough because sometimes
358+
// the score is -0.0 which equals to 0 even if it starts with a `-`
359+
if !strings.HasPrefix(fmt.Sprintf("%f", t.Points), "-") {
358360
leadingSpace = " "
359361
}
360362

361363
line := fmt.Sprintf("%v%.1f %v", leadingSpace, t.Points, t.Rule)
362-
line += strings.Repeat(" ", 28-len(line)) + t.Description + "\n"
364+
numberOfSpaces := 38 - len(line)
365+
if numberOfSpaces <= 0 {
366+
numberOfSpaces = 1
367+
}
368+
line += strings.Repeat(" ", numberOfSpaces) + t.Description + "\n"
363369
table += line
364370
}
365371

0 commit comments

Comments
 (0)