Skip to content
This repository
Browse code

Align rake notes.

  • Loading branch information...
commit 9299bfdcd387253d83b645c205b8df477f2d0940 1 parent 9fffef5
Anton Lindqvist authored December 26, 2011
3  railties/lib/rails/source_annotation_extractor.rb
@@ -22,7 +22,7 @@ class Annotation < Struct.new(:line, :tag, :text)
22 22
     # If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
23 23
     # Otherwise the string contains just line and text.
24 24
     def to_s(options={})
25  
-      s = "[%3d] " % line
  25
+      s = "[#{line.to_s.rjust(options[:indent])}]"
26 26
       s << "[#{tag}] " if options[:tag]
27 27
       s << text
28 28
     end
@@ -93,6 +93,7 @@ def extract_annotations_from(file, pattern)
93 93
   # Prints the mapping from filenames to annotations in +results+ ordered by filename.
94 94
   # The +options+ hash is passed to each annotation's +to_s+.
95 95
   def display(results, options={})
  96
+    options[:indent] = results.map { |f, a| a.map(&:line) }.flatten.max.to_s.size
96 97
     results.keys.sort.each do |file|
97 98
       puts "#{file}:"
98 99
       results[file].each do |note|
9  railties/test/application/rake/notes_test.rb
@@ -17,6 +17,7 @@ def teardown
17 17
         app_file "app/views/home/index.html.erb", "<% # TODO: note in erb %>"
18 18
         app_file "app/views/home/index.html.haml", "-# TODO: note in haml"
19 19
         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"
20 21
 
21 22
         boot_rails
22 23
         require 'rake'
@@ -27,10 +28,18 @@ def teardown
27 28
    
28 29
         Dir.chdir(app_path) do
29 30
           output = `bundle exec rake notes`
  31
+          lines = output.scan(/\[([0-9\s]+)\]/).flatten
30 32
         
31 33
           assert_match /note in erb/, output
32 34
           assert_match /note in haml/, output
33 35
           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
34 43
         end
35 44
       
36 45
       end

0 notes on commit 9299bfd

Martin Rehfeld

Is it intentional that this change introduces a subtle modification of the output format of rake notes as it leaves out the space between line number and tag.
I'm asking because this new format breaks the Ruby Metrics Plugin in Jenkins that would no longer parse the output correcty.

(Just in case, I have also proposed a change to the Metrics Plugin parser code: jenkinsci/rubymetrics-plugin#10)

Anton Lindqvist

Yikes! This was not my intention at all. I just submitted another pull request (mptre/rails@c5f4b20) with a fix and corresponding tests in order hopefully not introduce this bug again.

Sorry for the inconvenience!

Please sign in to comment.
Something went wrong with that request. Please try again.