diff --git a/spec/ameba/rule/layout/trailing_whitespace_spec.cr b/spec/ameba/rule/layout/trailing_whitespace_spec.cr index 0d63c112c..ff8580545 100644 --- a/spec/ameba/rule/layout/trailing_whitespace_spec.cr +++ b/spec/ameba/rule/layout/trailing_whitespace_spec.cr @@ -8,6 +8,28 @@ module Ameba::Rule::Layout expect_no_issues subject, "no-whitespace" end + it "passes a line ends with trailing CRLF sequence" do + expect_no_issues subject, "no-whitespace\r\n" + end + + it "fails if a line ends with trailing \\r character" do + source = expect_issue subject, <<-TEXT + carriage return at the end\r + # ^ error: Trailing whitespace detected + TEXT + + expect_correction source, "carriage return at the end" + end + + it "fails if there is a line with trailing tab" do + source = expect_issue subject, <<-TEXT + tab at the end\t + # ^ error: Trailing whitespace detected + TEXT + + expect_correction source, "tab at the end" + end + it "fails if there is a line with trailing whitespace" do source = expect_issue subject, "whitespace at the end \n" \ diff --git a/src/ameba/source.cr b/src/ameba/source.cr index 13682a459..994bbe8ef 100644 --- a/src/ameba/source.cr +++ b/src/ameba/source.cr @@ -48,7 +48,7 @@ module Ameba # source = Ameba::Source.new "a = 1\nb = 2", path # source.lines # => ["a = 1", "b = 2"] # ``` - getter lines : Array(String) { code.split('\n') } + getter lines : Array(String) { code.split(/\r?\n/) } # Returns AST nodes constructed by `Crystal::Parser`. #