Add rule namespaces: style, lint, layout (#63)

This commit is contained in:
V. Elenhaupt 2018-06-16 14:50:59 +03:00 committed by GitHub
parent d9f04af057
commit 4cb5328513
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 128 additions and 128 deletions

View file

@ -0,0 +1,42 @@
require "../../../spec_helper"
module Ameba::Rule::Layout
subject = LineLength.new
long_line = "*" * 81
describe LineLength do
it "passes if all lines are shorter than 80 symbols" do
source = Source.new "short line"
subject.catch(source).should be_valid
end
it "passes if line consists of 79 symbols" do
source = Source.new "*" * 80
subject.catch(source).should be_valid
end
it "fails if there is at least one line longer than 79 symbols" do
source = Source.new long_line
subject.catch(source).should_not be_valid
end
it "reports rule, pos and message" do
source = Source.new long_line, "source.cr"
subject.catch(source).should_not be_valid
issue = source.issues.first
issue.rule.should eq subject
issue.location.to_s.should eq "source.cr:1:81"
issue.message.should eq "Line too long"
end
context "properties" do
it "allows to configure max length of the line" do
source = Source.new long_line
rule = LineLength.new
rule.max_length = long_line.size
rule.catch(source).should be_valid
end
end
end
end

View file

@ -0,0 +1,37 @@
require "../../../spec_helper"
module Ameba::Rule::Layout
subject = TrailingBlankLines.new
describe TrailingBlankLines do
it "passes if there is no blank lines at the end" do
source = Source.new "no-blankline"
subject.catch(source).should be_valid
end
it "fails if there is a blank line at the end of a source" do
source = Source.new "a = 1\n \n "
subject.catch(source).should_not be_valid
end
it "passes if source is empty" do
source = Source.new ""
subject.catch(source).should be_valid
end
it "passes if last line is not blank" do
source = Source.new "\n\n\n puts 22"
subject.catch(source).should be_valid
end
it "reports rule, pos and message" do
source = Source.new "a = 1\n\n ", "source.cr"
subject.catch(source).should_not be_valid
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:3:1"
issue.message.should eq "Blank lines detected at the end of the file"
end
end
end

View file

@ -0,0 +1,27 @@
require "../../../spec_helper"
module Ameba::Rule::Layout
subject = TrailingWhitespace.new
describe TrailingWhitespace do
it "passes if all lines do not have trailing whitespace" do
source = Source.new "no-whispace"
subject.catch(source).should be_valid
end
it "fails if there is a line with trailing whitespace" do
source = Source.new "whitespace at the end "
subject.catch(source).should_not be_valid
end
it "reports rule, pos and message" do
source = Source.new "a = 1\n b = 2 ", "source.cr"
subject.catch(source).should_not be_valid
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:7"
issue.message.should eq "Trailing whitespace detected"
end
end
end