FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add support for more matching phrases by patrickdevivo · Pull Request #44 · augmentable-dev/tickgit · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion pkg/comments/comments.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func SearchFile(filePath string, reader io.Reader, cb func(*Comment)) error {
return nil
}
options, ok := LanguageParseOptions[lang]
if !ok { // TODO provide a default parse option?
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
return nil
}
commentParser, err := lege.NewParser(options)
Expand Down
14 changes: 10 additions & 4 deletions pkg/todos/report.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package todos

import (
"io"
"strings"
"text/template"
)

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

t, err := template.New("todos").Parse(DefaultTemplate)
t, err := template.New("todos").Parse(defaultTemplate)
if err != nil {
return err
}

// replace the phrase in the todo string with a "highlighted" version for console output
// TODO eventually make this configurable, for NO_COLOR output (or customization of color?)
for _, todo := range todos {
todo.String = strings.Replace(todo.String, todo.Phrase, "\u001b[33m"+todo.Phrase+"\u001b[0m", 1)
}

err = t.Execute(writer, todos)
if err != nil {
return err
Expand Down
30 changes: 21 additions & 9 deletions pkg/todos/todos.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package todos
import (
"bufio"
"context"
"regexp"
"strings"

"github.com/augmentable-dev/tickgit/pkg/blame"
Expand All @@ -16,6 +15,7 @@ import (
type ToDo struct {
comments.Comment
String string
Phrase string
Blame *blame.Blame
}

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

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

todo := ToDo{Comment: comment, String: s}
return &todo
for _, phrase := range matchPhrases {
s := comment.String()
if strings.Contains(s, phrase) {
todo := ToDo{
Comment: comment,
String: strings.Trim(s, " "),
Phrase: phrase,
}
return &todo
}
}

return nil
}

// NewToDos produces a list of ToDos from a list of comments
Expand Down
36 changes: 36 additions & 0 deletions pkg/todos/todos_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package todos

import (
"testing"

"github.com/augmentable-dev/lege"
"github.com/augmentable-dev/tickgit/pkg/comments"
)

func TestNewToDoNil(t *testing.T) {
collection := lege.NewCollection(lege.Location{}, lege.Location{}, lege.Boundary{}, "Hello World")
comment := comments.Comment{
Collection: *collection,
}
todo := NewToDo(comment)

if todo != nil {
t.Fatalf("did not expect a TODO, got: %v", todo)
}
}

func TestNewToDo(t *testing.T) {
collection := lege.NewCollection(lege.Location{}, lege.Location{}, lege.Boundary{}, "TODO Hello World")
comment := comments.Comment{
Collection: *collection,
}
todo := NewToDo(comment)

if todo == nil {
t.Fatalf("expected a TODO, got: %v", todo)
}

if todo.Phrase != "TODO" {
t.Fatalf("expected matched phrase to be TODO, got: %s", todo.Phrase)
}
}

Back | FazBrowse Home | New Git URL