turboladen / tailor

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

Line ending should not be included in >80 calculation #87

Closed acrmp closed 12 years ago

acrmp commented 12 years ago

Hi Steve,

Thanks for writing tailor. I noticed I was getting warnings displayed when my lines were exactly 80 characters in length (on master).

Looks like the trailing newline needs to be removed before comparison.

Thanks,

Andrew.

content = <<-eos
#{'#' * 80}
# Why the long face?
#{'#' * 80}
eos
File.open('test_file.rb', 'w') {|f| f.write(content)}
$ cat test_file.rb 
################################################################################
# Why the long face?
################################################################################

$ wc -L test_file.rb
80 test_file.rb

require 'tailor/file_line'

file = Pathname.new(File.join(Dir.getwd, 'test_file.rb'))
source = File.open(file, 'r')
source.each_line do |source_line|
  line = Tailor::FileLine.new(source_line, file, $.)
  puts line.end_with?("\n") if line.too_long?
end
Problems in test_file.rb [1]:
        Line is >80 characters (81)
true

Problems in test_file.rb [3]:
        Line is >80 characters (81)
true
turboladen commented 12 years ago

Thanks for the bug, Andrew, and the sweet example. I'm working on 1.0.0 release at the moment (adding indentation checking and some other bells and whistles), so I'll be sure to get this fixed up in there.

turboladen commented 12 years ago

Fixed in 56ff712c871f12ef13376c7d9204f6b49a15b906