Skip to content

Commit 6252ede

Browse files
committed
Merge pull request rails#4192 from mptre/master
Align rake notes
2 parents 38b0d6d + 9299bfd commit 6252ede

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

railties/lib/rails/source_annotation_extractor.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Annotation < Struct.new(:line, :tag, :text)
2222
# If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
2323
# Otherwise the string contains just line and text.
2424
def to_s(options={})
25-
s = "[%3d] " % line
25+
s = "[#{line.to_s.rjust(options[:indent])}]"
2626
s << "[#{tag}] " if options[:tag]
2727
s << text
2828
end
@@ -93,6 +93,7 @@ def extract_annotations_from(file, pattern)
9393
# Prints the mapping from filenames to annotations in +results+ ordered by filename.
9494
# The +options+ hash is passed to each annotation's +to_s+.
9595
def display(results, options={})
96+
options[:indent] = results.map { |f, a| a.map(&:line) }.flatten.max.to_s.size
9697
results.keys.sort.each do |file|
9798
puts "#{file}:"
9899
results[file].each do |note|

railties/test/application/rake/notes_test.rb

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def teardown
1717
app_file "app/views/home/index.html.erb", "<% # TODO: note in erb %>"
1818
app_file "app/views/home/index.html.haml", "-# TODO: note in haml"
1919
app_file "app/views/home/index.html.slim", "/ TODO: note in slim"
20+
app_file "app/controllers/application_controller.rb", 1000.times.map { "" }.join("\n") << "# TODO: note in ruby"
2021

2122
boot_rails
2223
require 'rake'
@@ -27,10 +28,18 @@ def teardown
2728

2829
Dir.chdir(app_path) do
2930
output = `bundle exec rake notes`
31+
lines = output.scan(/\[([0-9\s]+)\]/).flatten
3032

3133
assert_match /note in erb/, output
3234
assert_match /note in haml/, output
3335
assert_match /note in slim/, output
36+
assert_match /note in ruby/, output
37+
38+
assert_equal 4, lines.size
39+
assert_equal 4, lines[0].size
40+
assert_equal 4, lines[1].size
41+
assert_equal 4, lines[2].size
42+
assert_equal 4, lines[3].size
3443
end
3544

3645
end

0 commit comments

Comments
 (0)