Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rufo/erb_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initialize(code, **options)
def format
out = []
process_erb do |(type, content)|
if type == :code
if type == :code && !erb_comment?(content)
formatted_code = process_code(content)
indented_code = formatted_code.lines.join(" " * current_column)
out << " #{indented_code} "
Expand Down Expand Up @@ -176,4 +176,8 @@ def enable_code_mode
def disable_code_mode
@code_mode = false
end

def erb_comment?(code)
code.start_with?("#")
end
end
10 changes: 10 additions & 0 deletions spec/lib/rufo/erb_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,15 @@
result = subject.format("<%=yield%>")
expect(result).to eql("<%= yield %>")
end

it "handles native erb comments" do
result = subject.format("<%# locals: (item:, variant:) %>")
expect(result).to eql("<%# locals: (item:, variant:) %>")
end

it "handles ruby comments" do
result = subject.format("<% # TODO: fix this later %>")
expect(result).to eql("<% # TODO: fix this later %>")
end
end
end