@@ -2,7 +2,6 @@ package todos
22
33import (
44 "bytes"
5- "fmt"
65 "io/ioutil"
76 "path/filepath"
87 "strings"
@@ -13,12 +12,12 @@ import (
1312
1413// CStyleCommentOptions ...
1514var CStyleCommentOptions * lege.ParseOptions = & lege.ParseOptions {
16- BoundaryOptions : []lege.BoundaryOption {
17- lege.BoundaryOption {
15+ Boundaries : []lege.Boundary {
16+ lege.Boundary {
1817 Starts : []string {"//" },
1918 Ends : []string {"\n " },
2019 },
21- lege.BoundaryOption {
20+ lege.Boundary {
2221 Starts : []string {"/*" },
2322 Ends : []string {"*/" },
2423 },
@@ -27,8 +26,8 @@ var CStyleCommentOptions *lege.ParseOptions = &lege.ParseOptions{
2726
2827// HashStyleCommentOptions ...
2928var HashStyleCommentOptions * lege.ParseOptions = & lege.ParseOptions {
30- BoundaryOptions : []lege.BoundaryOption {
31- lege.BoundaryOption {
29+ Boundaries : []lege.Boundary {
30+ lege.Boundary {
3231 Starts : []string {"#" },
3332 Ends : []string {"\n " },
3433 },
@@ -51,8 +50,17 @@ var LanguageParseOptions map[Language]*lege.ParseOptions = map[Language]*lege.Pa
5150 "PHP" : CStyleCommentOptions ,
5251}
5352
54- // SearchFile ...
55- func SearchFile (filePath string ) ([]* lege.Collection , error ) {
53+ // ToDo represents a ToDo item
54+ type ToDo struct {
55+ FilePath string
56+ Line int
57+ Position int
58+ String string
59+ }
60+
61+ // SearchFile searches a file for comments. It infers the language
62+ func SearchFile (filePath string ) ([]* ToDo , error ) {
63+ todos := make ([]* ToDo , 0 )
5664 src , err := ioutil .ReadFile (filePath )
5765 if err != nil {
5866 return nil , err
@@ -61,7 +69,10 @@ func SearchFile(filePath string) ([]*lege.Collection, error) {
6169 if enry .IsVendor (filePath ) {
6270 return nil , nil
6371 }
64- options := LanguageParseOptions [lang ]
72+ options , ok := LanguageParseOptions [lang ]
73+ if ! ok {
74+ return nil , nil
75+ }
6576 commentParser , err := lege .NewParser (options )
6677 if err != nil {
6778 return nil , err
@@ -78,8 +89,15 @@ func SearchFile(filePath string) ([]*lege.Collection, error) {
7889 }
7990 s = strings .Replace (comment .String (), "TODO" , "" , 1 )
8091 s = strings .Trim (s , " " )
81- fmt .Printf ("%q\n " , s )
92+ // fmt.Printf("%q\n", s)
93+ todo := & ToDo {
94+ FilePath : filePath ,
95+ Line : comment .StartLocation .Line ,
96+ Position : comment .StartLocation .Pos ,
97+ String : s ,
98+ }
99+ todos = append (todos , todo )
82100 }
83101
84- return comments , nil
102+ return todos , nil
85103}
0 commit comments