Skip to content

Instantly share code, notes, and snippets.

@Pilooz
Created December 13, 2012 09:43
Show Gist options
  • Select an option

  • Save Pilooz/4275337 to your computer and use it in GitHub Desktop.

Select an option

Save Pilooz/4275337 to your computer and use it in GitHub Desktop.
Rake Task for listing #TODO, #THINK and # FIXME in Ruby projects
desc "show a todolist from all the TODO tags in the source"
task :todo do
underyellow = "\e[4;33m%s\e[0m"
underred = "\e[4;31m%s\e[0m"
undergreen = "\e[4;32m%s\e[0m"
undercolor = ""
color = ""
Dir.glob('{ctrl,model,layout,view,spec}/**/*.{rb,xhtml}') do |file|
lastline = todo = comment = long_comment = false
File.readlines(file).each_with_index do |line, lineno|
lineno += 1
comment = line =~ /^\s*?#.*?$/
long_comment = line =~ /^=begin/
long_comment = line =~ /^=end/
todo = true if line =~ /TODO|FIXME|THINK/ and (long_comment or comment)
todo = false if line.gsub('#', '').strip.empty?
todo = false unless comment or long_comment
undercolor = underyellow if line =~ /TODO/
undercolor = underred if line =~ /FIXME/
undercolor = undergreen if line =~ /THINK/
color = undercolor.gsub('4', '0')
if todo
unless lastline and lastline + 1 == lineno
puts
puts undercolor % "#{file}# #{lineno} : "
end
l = ' . ' + line.strip.gsub(/^#\s*/, '')
#print ' . ' unless l =~ /^-/
puts color % l
lastline = lineno
end
end # File.readlines
end
end # task :todo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment