Moved TodoFinder.init() to NewTodoFinder func to ensure init is not forgotten

This commit is contained in:
Samuel Hawksby-Robinson 2021-01-06 17:10:58 +00:00
parent 4723f2f47d
commit 2e514a4d9c
No known key found for this signature in database
GPG Key ID: 64CF99D4A64A1205
2 changed files with 6 additions and 5 deletions

View File

@ -14,8 +14,7 @@ const (
)
func main() {
tf := NewTodoFinder()
err := tf.Init()
tf, err := NewTodoFinder()
if err != nil {
panic(err)
}

View File

@ -24,15 +24,17 @@ type TodoFinder struct {
keywords []string
}
func NewTodoFinder() TodoFinder {
return TodoFinder{
func NewTodoFinder() (TodoFinder, error) {
tf := TodoFinder{
FoundTable: []*todo{},
foundTree: &node{Name: "root", Type: "dir"},
keywords: []string{"todo", "fixme"},
}
return tf, tf.init()
}
func (tf *TodoFinder) Init() (err error) {
func (tf *TodoFinder) init() (err error) {
tf.todoRegex, err = regexp.Compile(tf.buildRegexPattern())
if err != nil {
return err