There are improvements. Before I keep going on and on about your code I suggest you visit CodeReviewComments · golang/go Wiki · GitHub which is a nice list of topics to pay attention on.
Regarding:
https://github.com/asticode/gotodo/blob/master/todo.go#L38-L46
whenever I see nested if-blocks, I wonder whether they are masking for some boolean math that should be there but it isn’t. The way this block is written, you could remove at least one level of depth.
Regarding:
https://github.com/asticode/gotodo/blob/master/todo.go#L59-L63
Ditto. With an additional aspect that you are overwriting the err
passed in functions params with the one gotten by todos.extractFile
. Again, if by this point you don’t want to act on a directory, you can just return nil (I am not sure whether returning nil is the correct thing here. Early on you returned filepath.SkipDir
)
I haven’t executed the code yet, but I wonder what would happen if the comment looked like this:
/*
TODO: something*/
How would this if-block behave? https://github.com/asticode/gotodo/blob/master/todo.go#L86-L88 – I see you skip the head of the comment, but does not check the footer.
I do not know whether you read Nystrom’s blog post about variable naming. If you haven’t, it is a very nice read: Long Names Are Long – journal.stuffwithstuff.com
So I am noticing at least one unnecessarily long variable name: TODOFound
(which found is not a todo?)
OK. Now… this is totally a matter of personal opinion, feel free to discard as you will, but I feel using regex to extract assignee is a bit overkill, and probably slow. In the end, you want a very simple thing: find the position of first opening and closing parentheses, and subslice it. It could be accomplished with less, I assume. Check:
And finally, another matter of personal opinion and taste, I believe you could put some effort on the comments, by removing the trivial ones (such: https://github.com/asticode/gotodo/blob/master/todo.go#L37 for example), and improving the ones that matter, like this: https://github.com/asticode/gotodo/blob/master/todo.go#L29
Rob Pike’s once wrote a series of notes on C programming, and dedicated a whole topic about comments. It is also a good read: Rob Pike: Notes on Programming in C
I would highlight:
I tend to err on the side of eliminating comments, for several reasons. […] But I do comment sometimes. Almost exclusively, I use them as an introduction to what follows. Examples: explaining the use of global variables and types (the one thing I always comment in large programs); as an introduction to an unusual or critical procedure; or to mark off sections of a large computation.