turboladen / tailor

A RubyGem that allows for checking standard styling of Ruby files.
146 stars 18 forks source link

Incorrect indentation detected with consecutive multi-line ops #103

Closed turboladen closed 12 years ago

turboladen commented 12 years ago

v1.0.0 ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]

This renders incorrect results:

def friendly_time(time)
  hours = (Time.now - time).to_i / 3600
  minutes = (Time.now - time).to_i / 60 % 60
  seconds = (Time.now - time).to_i % 60

  if hours < 24
    "#{(hours > 0) ? "#{hours} hour" : '' }#{(hours > 1) ? 's' : ''}" +
      " #{(minutes > 0) ? "#{minutes} minute" : '' }#{(minutes > 1) ? 's' : ''}" +
      " #{seconds} second#{(seconds > 1) ? "s" : ''} ago"
  else
    time.to_s
  end
end
# problems:
#  1.
#    * position:  8:82
#    * property:  max_line_length
#    * message:   Line is 82 chars long, but should be 80.
#  2.
#    * position:  9:6
#    * property:  indentation_spaces
#    * message:   Line is indented to 6, but should be at 8.
#  3.
#    * position:  10:2
#    * property:  indentation_spaces
#    * message:   Line is indented to 2, but should be at 0.
#  4.
#    * position:  11:4
#    * property:  indentation_spaces
#    * message:   Line is indented to 4, but should be at 2.
#  5.
#    * position:  12:2
#    * property:  indentation_spaces
#    * message:   Line is indented to 2, but should be at 0.
#  6.
#    * position:  13:0
#    * property:  indentation_spaces
#    * message:   Line is indented to 0, but should be at -2.

Also, a negative expectation should never be set.

Note that this code:


if hours < 24
  "#{(hours > 0) ? "#{hours} hour" : '' }#{(hours > 1) ? 's' : ''}" +
    " #{(minutes > 0) ? "#{minutes} minute" : '' }#{(minutes > 1) ? 's' : ''}" +
    " #{seconds} second#{(seconds > 1) ? "s" : ''} ago"
else
  time.to_s
end

...only yields this error:

# problems:
#  1.
#    * position:  4:4
#    * property:  indentation_spaces
#    * message:   Line is indented to 4, but should be at 6.