Skip to content

Commit

Permalink
Move ruby open and close block regex into constant
Browse files Browse the repository at this point in the history
Co-authored-by: Elia Schito <[email protected]>
  • Loading branch information
FrancescoAiello01 and elia committed Mar 31, 2023
1 parent 0345476 commit ab85c77
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 @@ -53,6 +53,8 @@ class Error < StandardError; end
# is nil when the parsing is broken, meaning it's an open expression
Ripper.sexp(code).nil?
end.freeze
RUBY_CLOSE_BLOCK = /\Aend\z/
RUBY_REOPEN_BLOCK = /\A(else|elsif\b(.*)|when\b(.*))\z/

RUBOCOP_STDIN_MARKER = "===================="

Expand Down Expand Up @@ -303,11 +305,11 @@ def format_erb_tags(string)
erb_open << ' ' unless ruby_code.start_with?('#')

case ruby_code
when /\Aend\z/
when RUBY_CLOSE_BLOCK
full_erb_tag = "#{erb_open}#{ruby_code} #{erb_close}"
tag_stack_pop('%erb%', ruby_code)
html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag)
when /\A(else|elsif\b(.*)|when\b(.*))\z/
when RUBY_REOPEN_BLOCK
full_erb_tag = "#{erb_open}#{ruby_code} #{erb_close}"
tag_stack_pop('%erb%', ruby_code)
html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag)
Expand Down

0 comments on commit ab85c77

Please sign in to comment.