BROKEN - This commit breaks the original functionality, but introduces an effective method of representing found todos in both a table and tree format.
This commit is contained in:
parent
2e275015c3
commit
602a263f55
31
main.go
31
main.go
|
@ -6,8 +6,6 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
// TODO implement dynamic comment token selection, could maybe work similar to entityTracker{}
|
||||
|
@ -20,8 +18,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
keywords = []string{"todo", "fixme"}
|
||||
found []todo
|
||||
keywords = []string{"todo", "fixme"}
|
||||
|
||||
// todoMode tracks if subsequent comment lines should be included in the last to-do's description
|
||||
todoMode = false
|
||||
|
@ -32,6 +29,19 @@ type todo struct {
|
|||
Description string
|
||||
LineNumber int
|
||||
RelatedFuncOrType string
|
||||
filePathSlice []string
|
||||
}
|
||||
|
||||
func (t *todo) Path() []string {
|
||||
if t.filePathSlice != nil {
|
||||
return t.filePathSlice
|
||||
}
|
||||
|
||||
sp := strings.Split(t.Filepath, "/")
|
||||
sp = trimPath(sp)
|
||||
t.filePathSlice = sp
|
||||
|
||||
return t.filePathSlice
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -39,8 +49,6 @@ func main() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
spew.Dump(found)
|
||||
}
|
||||
|
||||
func processFilesInDir(dir string) error {
|
||||
|
@ -100,7 +108,7 @@ func processFilesInDir(dir string) error {
|
|||
if todoMode {
|
||||
l = strings.TrimSpace(l)
|
||||
if l[:2] == "//" {
|
||||
found[len(found)-1].Description += "\n" + l[2:]
|
||||
//found[len(found)-1].Description += "\n" + l[2:]
|
||||
} else {
|
||||
todoMode = false
|
||||
}
|
||||
|
@ -108,7 +116,14 @@ func processFilesInDir(dir string) error {
|
|||
|
||||
continue
|
||||
}
|
||||
found = append(found, todo{filepath, string(results[1]), i + 1, et.Current()})
|
||||
td := &todo{
|
||||
Filepath: filepath,
|
||||
Description: string(results[1]),
|
||||
LineNumber: i + 1,
|
||||
RelatedFuncOrType: et.Current(),
|
||||
}
|
||||
println(td)
|
||||
//found = append(found, todo{filepath, string(results[1]), i + 1, et.Current()})
|
||||
todoMode = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package main
|
||||
|
||||
type node struct {
|
||||
Name string
|
||||
Type string
|
||||
Nodes []*node
|
||||
Todos []*todo
|
||||
}
|
||||
|
||||
type todoFinder struct {
|
||||
foundTable map[string]*todo
|
||||
foundTree *node
|
||||
}
|
||||
|
||||
func NewTodoFinder() *todoFinder {
|
||||
return &todoFinder{
|
||||
foundTable: map[string]*todo{},
|
||||
foundTree: &node{Name: "root", Type: "dir"},
|
||||
}
|
||||
}
|
||||
|
||||
func (tf *todoFinder) AddTodo(t *todo) {
|
||||
tf.foundTable[t.Filepath] = t
|
||||
tf.foundTree.AddToTree(t.Path(), t)
|
||||
}
|
||||
|
||||
func (n *node) AddToTree(path []string, t *todo) {
|
||||
if len(path) == 0 {
|
||||
n.Todos = append(n.Todos, t)
|
||||
return
|
||||
}
|
||||
|
||||
var nn *node
|
||||
for _, cn := range n.Nodes {
|
||||
if cn.Name == path[0] {
|
||||
nn = cn
|
||||
}
|
||||
}
|
||||
|
||||
if nn == nil {
|
||||
nn = &node{
|
||||
Name: path[0],
|
||||
Type: n.getTypeFromPath(path),
|
||||
}
|
||||
|
||||
n.Nodes = append(n.Nodes, nn)
|
||||
}
|
||||
|
||||
nn.AddToTree(path[1:], t)
|
||||
}
|
||||
|
||||
func (n node) getTypeFromPath(path []string) string {
|
||||
if len(path) == 1 {
|
||||
return "file"
|
||||
}
|
||||
|
||||
return "dir"
|
||||
}
|
||||
|
||||
func trimPath(path []string) []string {
|
||||
ignoreList := []string{"..", "status-go"}
|
||||
if path[0] == ignoreList[0] && path[1] == ignoreList[1] {
|
||||
path = path[2:]
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNode_AddToTree(t *testing.T) {
|
||||
n := &node{Name: "root", Type: "dir"}
|
||||
td := &todo{
|
||||
Filepath: "../status-go/admin/sales/donkeys/pokemon/gif.go",
|
||||
Description: "this looks borken",
|
||||
LineNumber: 19224,
|
||||
RelatedFuncOrType: "",
|
||||
}
|
||||
|
||||
n.AddToTree(td.Path(), td)
|
||||
|
||||
spew.Dump(n)
|
||||
}
|
Loading…
Reference in New Issue