Line lenght: 80 symbols

This commit is contained in:
Vitalii Elenhaupt 2017-11-06 08:54:59 +02:00
parent 374956f3dd
commit 1a3bb3629e
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
2 changed files with 5 additions and 5 deletions

View file

@ -2,7 +2,7 @@ require "../../spec_helper"
module Ameba::Rules module Ameba::Rules
subject = LineLength.new subject = LineLength.new
long_line = "*" * 80 long_line = "*" * 81
describe LineLength do describe LineLength do
it "passes if all lines are shorter than 80 symbols" do it "passes if all lines are shorter than 80 symbols" do
@ -11,7 +11,7 @@ module Ameba::Rules
end end
it "passes if line consists of 79 symbols" do it "passes if line consists of 79 symbols" do
source = Source.new "*" * 79 source = Source.new "*" * 80
subject.catch(source).should be_valid subject.catch(source).should be_valid
end end
@ -27,7 +27,7 @@ module Ameba::Rules
error = source.errors.first error = source.errors.first
error.rule.should eq subject error.rule.should eq subject
error.pos.should eq 1 error.pos.should eq 1
error.message.should eq "Line too long (80 symbols)" error.message.should eq "Line too long (81 symbols)"
end end
end end
end end

View file

@ -1,10 +1,10 @@
module Ameba::Rules module Ameba::Rules
# A rule that disallows lines longer than 79 symbols. # A rule that disallows lines longer than 80 symbols.
# #
struct LineLength < Rule struct LineLength < Rule
def test(source) def test(source)
source.lines.each_with_index do |line, index| source.lines.each_with_index do |line, index|
next unless line.size > 79 next unless line.size > 80
source.error self, index + 1, source.error self, index + 1,
"Line too long (#{line.size} symbols)" "Line too long (#{line.size} symbols)"
end end