Skip to content

Commit 7040cf4

Browse files
committed
first pass at some work to support more match phrases
not yet configurable, but adds matching for "TODO", "FIXME", "OPTIMIZE", "HACK", "XXX", "WTF", "LEGACY" and their @ + lowerCase version equivalents
1 parent fa7055a commit 7040cf4

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

pkg/comments/comments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func SearchFile(filePath string, reader io.Reader, cb func(*Comment)) error {
4343
return nil
4444
}
4545
options, ok := LanguageParseOptions[lang]
46-
if !ok { // TODO provide a default parse option?
46+
if !ok { // TODO provide a default parse option for when we don't know how to handle a language? I.e. default to CStyle comments say
4747
return nil
4848
}
4949
commentParser, err := lege.NewParser(options)

pkg/todos/report.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package todos
22

33
import (
44
"io"
5+
"strings"
56
"text/template"
67
)
78

8-
// DefaultTemplate is the default report template
9-
const DefaultTemplate = `
9+
const defaultTemplate = `
1010
{{- range $index, $todo := . }}
11-
{{ print "\u001b[33m" }}TODO{{ print "\u001b[0m" }}: {{ .String }}
11+
{{ .String }}
1212
=> {{ .Comment.FilePath }}:{{ .Comment.StartLocation.Line }}:{{ .Comment.StartLocation.Pos }}
1313
{{- if .Blame }}
1414
=> added {{ .TimeAgo }} by {{ .Blame.Author }} in {{ .Blame.SHA }}
@@ -22,11 +22,17 @@ no todos 🎉
2222
// WriteTodos renders a report of todos
2323
func WriteTodos(todos ToDos, writer io.Writer) error {
2424

25-
t, err := template.New("todos").Parse(DefaultTemplate)
25+
t, err := template.New("todos").Parse(defaultTemplate)
2626
if err != nil {
2727
return err
2828
}
2929

30+
// replace the phrase in the todo string with a "highlighted" version for console output
31+
// TODO eventually make this configurable, for NO_COLOR output (or customization of color?)
32+
for _, todo := range todos {
33+
todo.String = strings.Replace(todo.String, todo.Phrase, "\u001b[33m"+todo.Phrase+"\u001b[0m", 1)
34+
}
35+
3036
err = t.Execute(writer, todos)
3137
if err != nil {
3238
return err

pkg/todos/todos.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package todos
33
import (
44
"bufio"
55
"context"
6-
"regexp"
76
"strings"
87

98
"github.com/augmentable-dev/tickgit/pkg/blame"
@@ -16,6 +15,7 @@ import (
1615
type ToDo struct {
1716
comments.Comment
1817
String string
18+
Phrase string
1919
Blame *blame.Blame
2020
}
2121

@@ -32,16 +32,28 @@ func (t *ToDo) TimeAgo() string {
3232

3333
// NewToDo produces a pointer to a ToDo from a comment
3434
func NewToDo(comment comments.Comment) *ToDo {
35-
s := comment.String()
36-
if !strings.Contains(s, "TODO") {
37-
return nil
35+
// FIXME this should be configurable and probably NOT hardcoded here
36+
// in fact, this list might be too expansive for a sensible default
37+
startingMatchPhrases := []string{"TODO", "FIXME", "OPTIMIZE", "HACK", "XXX", "WTF", "LEGACY"}
38+
var matchPhrases []string
39+
for _, phrase := range startingMatchPhrases {
40+
// populates matchPhrases with the contents of startingMatchPhrases plus the @+lowerCase version of each phrase
41+
matchPhrases = append(matchPhrases, phrase, "@"+strings.ToLower(phrase))
3842
}
39-
re := regexp.MustCompile(`TODO(:|,)?`)
40-
s = re.ReplaceAllLiteralString(comment.String(), "")
41-
s = strings.Trim(s, " ")
4243

43-
todo := ToDo{Comment: comment, String: s}
44-
return &todo
44+
for _, phrase := range matchPhrases {
45+
s := comment.String()
46+
if strings.Contains(s, phrase) {
47+
todo := ToDo{
48+
Comment: comment,
49+
String: strings.Trim(s, " "),
50+
Phrase: phrase,
51+
}
52+
return &todo
53+
}
54+
}
55+
56+
return nil
4557
}
4658

4759
// NewToDos produces a list of ToDos from a list of comments

0 commit comments

Comments
 (0)