Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't chomp off letters in whitespace normalizing

  • Loading branch information...
commit c10743de75d0e420adf9def4730f80980bb99903 1 parent f954f7d
@kneath kneath authored
Showing with 12 additions and 4 deletions.
  1. +11 −3 lib/kss/comment_parser.rb
  2. +1 −1  test/comment_parser_test.rb
View
14 lib/kss/comment_parser.rb
@@ -108,7 +108,8 @@ def parse_blocks
# Normalizes the comment block to ignore any consistent preceding
# whitespace. Consistent means the same amount of whitespace on every line
- # of the comment block.
+ # of the comment block. Also strips any whitespace at the start and end of
+ # the whole block.
#
# Returns a String of normalized text.
def normalize(text_block)
@@ -117,8 +118,15 @@ def normalize(text_block)
# Strip consistent indenting by measuring first line's whitespace
indent_size = nil
unindented = text_block.split("\n").collect do |line|
- indent_size = line.scan(/^\s*/)[0].to_s.size if indent_size.nil?
- line == "" ? "" : line.slice(indent_size, line.length - 1)
+ preceding_whitespace = line.scan(/^\s*/)[0].to_s.size
+ indent_size = preceding_whitespace if indent_size.nil?
+ if line == ""
+ ""
+ elsif indent_size <= preceding_whitespace
+ line.slice(indent_size, line.length - 1)
+ else
+ line
+ end
end.join("\n")
unindented.strip
View
2  test/comment_parser_test.rb
@@ -27,7 +27,7 @@ def setup
end
test "parses the multi-line comment syntax" do
- assert_equal " yuuuup ", Kss::CommentParser.parse_multi_line("/* yuuuup */")
+ assert_equal " yuuuup", Kss::CommentParser.parse_multi_line("/* yuuuup */")
end
test "finds single-line comment styles" do
Please sign in to comment.
Something went wrong with that request. Please try again.