todo-to-docs/main.go

62 lines
1.1 KiB
Go
Raw Normal View History

package main
import (
2021-01-05 11:16:34 +00:00
"fmt"
"github.com/davecgh/go-spew/spew"
2021-01-05 11:16:34 +00:00
"unicode"
)
// TODO implement dynamic comment token selection, could maybe work similar to entityTracker{}
2021-01-05 11:16:34 +00:00
// TODO check if to-do is just above a function or struct, if so assume the to-do is about the function
2021-01-05 11:16:34 +00:00
const (
statusDir = "../status-go"
2021-01-05 14:44:31 +00:00
ignore = statusDir + "/vendor"
)
var (
keywords = []string{"todo", "fixme"}
)
func main() {
tf := NewTodoFinder()
err := tf.FindInDir(statusDir)
if err != nil {
panic(err)
}
spew.Dump(tf.foundTree)
}
func isGoFile(name string) bool {
if len(name) < 3 {
return false
}
last := name[len(name)-3:]
return last == ".go"
}
2021-01-05 11:16:34 +00:00
func buildRegexPattern(keywords []string) string {
kwp := makeRegexKeywords(keywords)
2021-01-05 11:44:48 +00:00
return fmt.Sprintf("//.*((%s)(.*))", kwp)
2021-01-05 11:16:34 +00:00
}
2021-01-05 12:06:41 +00:00
func makeRegexKeywords(keywords []string) (out string) {
2021-01-05 11:16:34 +00:00
for i, kw := range keywords {
for _, r := range kw {
lower := unicode.ToLower(r)
upper := unicode.ToUpper(r)
out += fmt.Sprintf("[%s,%s]", string(lower), string(upper))
}
if i+1 < len(keywords) {
out += "|"
}
}
2021-01-05 12:06:41 +00:00
return
2021-01-05 11:16:34 +00:00
}