This post originated from an RSS feed registered with Ruby Buzz
by Jan Lelis.
Original Post: Organise your code comments with rake notes:todo!
Feed Title: rbJ*_*L.net
Feed URL: http://feeds.feedburner.com/rbJL
Feed Description: Hi, I am a fan of Ruby and like to explore it and the world around ;).
So I started this blog, where I am publishing code snippets, tutorials for beginners as well as general thoughts about Ruby, the web or programming in general.
Lots of IDEs (e.g. Netbeans) and some editors (e.g. gedit with plugins) have a nice feature: They show comments, which start with something like TODO or FIXME. Those annotations are quickly written and they make it harder to forget some things you wanted to (or have to) do.
I have just discovered that Rails has this feature already built-in!
rake notes
Just browse to your rails directory and type one of the following rake tasks:
It will show a nice comprehensive list of the files and lines, which have TODO, FIXME, or OPTIMIZE annotations. Note, that they are case sensitive and have to be written at the beginning of a comment. The shortcut rake notes combines the three of them.
You can also use your own words, but the resulting syntax is not so cool anymore…:
rake notes:custom ANNOTATION=COOL
Do not forget, that your own annotations are also case sensitive.
Search for thoughts
You can abuse the last command, to search through your whole rails project comments. This is possible, because the pattern is inserted as a part of this regexp: /#\s*(find_me):?\s*(.*)$/. So it is possible to run
rake notes:custom ANNOTATION=.*find_me
It works, but probably, the output after the line number is not that speaking anymore… But you can work around that by adding brackets:
rake notes:custom ANNOTATION=\(.*find_me.*\)
You have to escape some of the characters you pass (e.g. the brackets). One last hint: to use spaces in the search pattern, you can do something like this: find\\sme
I also noticed a little (but unimportant) bug.. because of the easy regexp, which is used for getting the only the comments, it sometimes gets false positives, when # is used for string interpolation.