There are a lot of terminal commands floating around that will list the TODO comments in your source code, but I’ve always found their output format lacking. Last week I decided to come up with something better. It’s language agnostic and it organizes everything into vertical columns to make reading easier:
shell
ack -i \
-o \
--group \
--color \
--sort-files "\b(TODO|FIX(ME)?|OPTIMIZE|BUG)(\(\w+\))?: (.*)" \
--ignore-dir={.git,node_modules,vendor,Pods} \
| perl -pe "s/:/\t/" \
| perl -pe "s/\t(\w+)(\(\w+\))?:(.*)/\t\$1:\$3 \$2/"
Here’s a breakdown of the options we’re using, and a few others you might find useful:
Option | Description |
---|---|
--color |
Highlight the matching text |
-follow |
Follow symbolic links |
--group |
Group matches by filename |
-i |
Ignore the case of matches |
-n |
Don’t search within subdirectories |
-o |
Display only the matched text1 |
--sort-files |
Sort the outputted files in alphabetical order |
--ignore-dir |
A list of directories that should be ignored |
Updates
- Fixed a bug where words such as “suffix” were captured, and added examples for ignoring directories. — 17 April 2016
- Added support files whose names begin with a period. — 30 July 2016
- Moved Go-style attribution to the end of the comment. This should make the list easier to scan. For example, “XYZ(who): Comment text” is now displayed as “XYZ: Comment text (who)”. — 25 May 2014
- Added support for “BUG” and Go-style attributed comments such as “BUG(who)”. — 29 April 2014
-
When combined with wildcard matching, this helps us discard any tabs or spaces that come before the comment. ↩