Skip to content

Commit

Permalink
fix(markdown): output a different message if no todos found
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Apr 6, 2024
1 parent a409c1d commit 72a8450
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
31 changes: 19 additions & 12 deletions pkg/output/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,23 @@ import (
type MarkdownOutput struct{}

// Convert to a markdown table
// @todo(sje): implement report
func (o MarkdownOutput) generate(report []scanner.Report) ([]byte, error) {
res := [][]string{
{"File", "Line Number", "Author", "Message"},
{"---", "---", "---", "---"},
}
var res [][]string

if len(report) > 0 {
res = [][]string{
{"File", "Line Number", "Author", "Message"},
{"---", "---", "---", "---"},
}

for _, item := range report {
res = append(res, []string{
fmt.Sprintf("[%s](%s#L%d)", item.File, item.File, item.LineNumber),
strconv.Itoa(item.LineNumber),
fmt.Sprintf("%s <%s>", item.Author, item.AuthorEmail),
item.Msg,
})
for _, item := range report {
res = append(res, []string{
fmt.Sprintf("[%s](%s#L%d)", item.File, item.File, item.LineNumber),
strconv.Itoa(item.LineNumber),
fmt.Sprintf("%s <%s>", item.Author, item.AuthorEmail),
item.Msg,
})
}
}

output := strings.Join([]string{
Expand All @@ -56,6 +59,10 @@ func (o MarkdownOutput) generate(report []scanner.Report) ([]byte, error) {
output += fmt.Sprintf("%s\n", strings.TrimSpace(strings.Join(line, " | ")))
}

if len(report) == 0 {
output += "πŸŽ‰πŸŽ‰πŸŽ‰ Woohoo! Nothing to do πŸŽ‰πŸŽ‰πŸŽ‰\n"
}

return []byte(output), nil
}

Expand Down
4 changes: 1 addition & 3 deletions toodaloo.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

> Generated by [Toodaloo](https://toodaloo.dev)
| File | Line Number | Author | Message |
| --- | --- | --- | --- |
| [pkg/output/markdown.go](pkg/output/markdown.go#L30) | 30 | Simon Emms <[email protected]> | implement report |
πŸŽ‰πŸŽ‰πŸŽ‰ Woohoo! Nothing to do πŸŽ‰πŸŽ‰πŸŽ‰

0 comments on commit 72a8450

Please sign in to comment.