Notes

grep annotations in source files

This lib provides a Ruby library and command line tool to find annotations in source files such as:

  • TODO

  • FIXME

  • OPTIMIZE

Custom tags can also be found.

The purpose of this code is to get a generic version of the ‘rake notes’ command (only used for Ruby on Rails applications). It will look for tags recursively in every given files (or in current directory by default).

Installation

Notes is available on Rubygems.org and can be installed with:

$ gem install notes

This command needs Rubygems (rubygems package on Ubuntu).

Note: it depends on rak version = 1.0 and rainbow version >= 1.1.

Usage

Command line tool

notes [options] [file...]

For details, see the help.

$ ruby notes --help
Usage: notes [options] [file...]
Search recursively for annotations in source code.
By default, notes will search for all annotations in current directory.
Available options:
    -a, --all                        Search TODO, FIXME and OPTIMIZE annotations
    -t, --todo                       Search TODO annotations
    -f, --fixme                      Search FIXME annotations
    -z, --optimize                   Search OPTIMIZE annotations
    -c, --custom=TAG                 Search TAG annotations
    -o, --out=FILE                   Save output in FILE
    -v, --version                    Print notes version
Example: notes -ac IMPROVE test.c lib
will search for TODO, FIXME, OPTIMIZE and IMPROVE annotations in test.c file and lib directory.

Another example:

$ notes test/data/sample.c
../test/data/sample.c:16: TODO: first thing to do
../test/data/sample.c:26: FIXME: first fixme thing
../test/data/sample.c:32: TODO: second todo thing!
../test/data/sample.c:42: OPTIMIZE: make it better
../test/data/sample.c:47: TODO: hello world

If the terminal allows it, colors will be displayed for files and tags.

Another again:

$ notes -o TODO.txt test/data/sample.c

will write all notes to a TODO.txt file. It will look like that:

* [TODO    ] ../test/data/sample.c (16): first thing to do
* [FIXME   ] ../test/data/sample.c (26): first fixme thing
* [TODO    ] ../test/data/sample.c (32): second todo thing!
* [OPTIMIZE] ../test/data/sample.c (42): make it better
* [TODO    ] ../test/data/sample.c (47): hello world

Lib

This code can be used as a Ruby lib. Let’s see how it works in irb:

$ irb
>> require 'notes'
>> AnnotationExtractor.tags << "FOO"                    # Add custom tag
>> notes = AnnotationExtractor.new "test/data/sample.c" # Parse file
>> notes.list                                           # Return the array of annotations
>> notes.get "FIXME"                                    # Return the array of FIXME annotations only
>> notes.write "TODO.rdoc"                              # Write all annotations in a file

License

------------------------------------------------------------------------------
 "THE BEER-WARE LICENSE" (Revision 42):
 <[email protected]> wrote this gem. As long as you retain this notice
 you can do whatever you want with this stuff. If we meet some day, and you
 think this stuff is worth it, you can buy me a beer in return. Vivien Didelot
------------------------------------------------------------------------------