-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
48 lines (36 loc) · 1.23 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'bundler/gem_tasks'
task :default => [ :notes ]
desc 'Enumerate annotations. Optionally takes a pipe-separated list of tags to process'
task :notes, :types do |t, args|
args.with_defaults :types => 'FIXME|TODO'
types = args[:types].split '|'
finder = /.*# ?(?<type>[A-Z]+):? (?<note>.+)$/
result = Hash.new { |hash, key| hash[key] = {} }
`git ls-files`.split("\n").each do |p|
path = Pathname(p)
line_number = 0
path.each_line do |line|
line_number += 1
if match = finder.match(line)
result[path][line_number] = { :type => match[:type], :note => match[:note] } if types.include? match[:type]
end
end rescue nil
end
numbers = []
result.each do |path, lines|
lines.each do |number, note|
numbers << number
end
end
number_width = numbers.max.to_s.length
type_width = types.max_by { |type| type.to_s.length }.to_s.length
result.each do |path, lines|
puts "\e[1m#{path}\e[0m:"
lines.each do |number, note|
line_number = "[\e[1m#{number.to_s.rjust(number_width)}\e[0m]"
type = "[\e[0;37m#{note[:type]}\e[0m]"
puts " * #{line_number} #{type.ljust(type_width + type.length - note[:type].length)} #{note[:note]}"
end
puts
end
end