mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add rule namespaces: style, lint, layout (#63)
This commit is contained in:
parent
d9f04af057
commit
4cb5328513
71 changed files with 128 additions and 128 deletions
42
spec/ameba/rule/layout/line_length_spec.cr
Normal file
42
spec/ameba/rule/layout/line_length_spec.cr
Normal 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
|
37
spec/ameba/rule/layout/trailing_blank_lines_spec.cr
Normal file
37
spec/ameba/rule/layout/trailing_blank_lines_spec.cr
Normal 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
|
27
spec/ameba/rule/layout/trailing_whitespace_spec.cr
Normal file
27
spec/ameba/rule/layout/trailing_whitespace_spec.cr
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue