diff --git a/lib/rufo/erb_formatter.rb b/lib/rufo/erb_formatter.rb index 0bc56dbe..49cd390d 100644 --- a/lib/rufo/erb_formatter.rb +++ b/lib/rufo/erb_formatter.rb @@ -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} " @@ -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 diff --git a/spec/lib/rufo/erb_formatter_spec.rb b/spec/lib/rufo/erb_formatter_spec.rb index e45e20e3..9ad8816c 100644 --- a/spec/lib/rufo/erb_formatter_spec.rb +++ b/spec/lib/rufo/erb_formatter_spec.rb @@ -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