Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New to do function #59

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion cmd/tickgit/commands/todos.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

var csvOutput bool
var startingMatchPhrases []string = []string{"TODO", "FIXME", "OPTIMIZE", "HACK", "XXX", "WTF", "LEGACY"}

func init() {
todosCmd.Flags().BoolVar(&csvOutput, "csv-output", false, "specify whether or not output should be in CSV format")
Expand Down Expand Up @@ -47,7 +48,7 @@ var todosCmd = &cobra.Command{

foundToDos := make(todos.ToDos, 0)
err = comments.SearchDir(dir, func(comment *comments.Comment) {
todo := todos.NewToDo(*comment)
todo := todos.NewToDo(*comment, startingMatchPhrases)
if todo != nil {
foundToDos = append(foundToDos, todo)
s.Suffix = fmt.Sprintf(" %d TODOs found", len(foundToDos))
Expand Down
12 changes: 5 additions & 7 deletions pkg/todos/todos.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ func (t *ToDo) TimeAgo() string {
}

// NewToDo produces a pointer to a ToDo from a comment
func NewToDo(comment comments.Comment) *ToDo {
func NewToDo(comment comments.Comment, matchPhrases []string) *ToDo {
// 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 {
// in fact, this list might be too expansive for a sensible defaul
for _, phrase := range matchPhrases {
// populates matchPhrases with the contents of startingMatchPhrases plus the @+lowerCase version of each phrase
matchPhrases = append(matchPhrases, phrase, "@"+strings.ToLower(phrase))
}
Expand All @@ -55,10 +53,10 @@ func NewToDo(comment comments.Comment) *ToDo {
}

// NewToDos produces a list of ToDos from a list of comments
func NewToDos(comments comments.Comments) ToDos {
func NewToDos(comments comments.Comments, matchPhrases []string) ToDos {
todos := make(ToDos, 0)
for _, comment := range comments {
todo := NewToDo(*comment)
todo := NewToDo(*comment, matchPhrases)
if todo != nil {
todos = append(todos, todo)
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/todos/todos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"github.com/augmentable-dev/tickgit/pkg/comments"
)

var startingMatchPhrases []string = []string{"TODO", "FIXME", "OPTIMIZE", "HACK", "XXX", "WTF", "LEGACY"}

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

if todo != nil {
t.Fatalf("did not expect a TODO, got: %v", todo)
Expand All @@ -24,7 +26,7 @@ func TestNewToDo(t *testing.T) {
comment := comments.Comment{
Collection: *collection,
}
todo := NewToDo(comment)
todo := NewToDo(comment, startingMatchPhrases)

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