Skip to content

Commit

Permalink
Handle multiline ERB comments
Browse files Browse the repository at this point in the history
Fixes #431
  • Loading branch information
glebm committed Mar 26, 2022
1 parent eb97672 commit c2c257d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/i18n/tasks/scanners/erb_ast_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@ def transform_misparsed_comment(node)
node.children[2]&.type == :code &&
node.children[3].nil?
code_node = node.children[2]

# Prepend # to each line to make it a valid Ruby comment.
code = code_node.children[0].split("\n").map do |line|
next line if line =~ /^\s*#/
"##{line}"
end.join("\n")

node.updated(
nil,
[nil, nil, code_node.updated(nil, ["##{code_node.children[0]}"]), nil]
[nil, nil, code_node.updated(nil, [code]), nil]
)
end

Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/used_keys/app/views/application/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ I18n.t("this_should_not")
<% end %>
<%# this should not fail: ' %>
<%# this is a multiline comment
it's totally fine
nothing should fail %>
</h3>

0 comments on commit c2c257d

Please sign in to comment.