Skip to content

Commit

Permalink
Extract the regexp for spacing chars into a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Feb 26, 2024
1 parent 4ef6e49 commit c5d3476
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/erb/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def format(q)

class Error < StandardError; end

SPACES = /\s+/m

# https://stackoverflow.com/a/317081
ATTR_NAME = %r{[^\r\n\t\f\v= '"<>]*[^\r\n\t\f\v= '"<>/]} # not ending with a slash
UNQUOTED_VALUE = %r{[^<>'"\s]+}
Expand Down Expand Up @@ -147,7 +149,7 @@ def format_attributes(tag_name, attrs, tag_closing)
next
end

value_parts = value[1...-1].strip.split(/\s+/)
value_parts = value[1...-1].strip.split(SPACES)
value_parts.sort_by!(&@css_class_sorter) if name == 'class' && @css_class_sorter

full_attr = "#{name}=#{value[0]}#{value_parts.join(" ")}#{value[-1]}"
Expand Down Expand Up @@ -232,7 +234,7 @@ def format_text(text)

return if text.match?(/\A\s*\z/m) # empty

text = text.gsub(/\s+/m, ' ').strip
text = text.gsub(SPACES, ' ').strip

offset = indented("").size
# Restore full line width if there are less than 40 columns available
Expand Down

0 comments on commit c5d3476

Please sign in to comment.