From f988079d0ba601cbc5c368de3addf0d5e7b64779 Mon Sep 17 00:00:00 2001 From: Kazuki Nishikawa Date: Wed, 24 Dec 2025 17:31:54 +0900 Subject: [PATCH 1/2] Support ERB whitespace trimming tag fixes: #335 --- lib/rufo/erb_formatter.rb | 2 +- spec/lib/rufo/erb_formatter_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/rufo/erb_formatter.rb b/lib/rufo/erb_formatter.rb index 49cd390d..3f146c45 100644 --- a/lib/rufo/erb_formatter.rb +++ b/lib/rufo/erb_formatter.rb @@ -8,7 +8,7 @@ def initialize(src) end def stags - ["<%==", "<%+={0,2}"] + super + ["<%-", "<%==", "<%+={0,2}"] + super end def etags diff --git a/spec/lib/rufo/erb_formatter_spec.rb b/spec/lib/rufo/erb_formatter_spec.rb index 9ad8816c..3820a049 100644 --- a/spec/lib/rufo/erb_formatter_spec.rb +++ b/spec/lib/rufo/erb_formatter_spec.rb @@ -99,5 +99,25 @@ result = subject.format("<% # TODO: fix this later %>") expect(result).to eql("<% # TODO: fix this later %>") end + + it "handles leading whitespace trim tag" do + result = subject.format('<%- if controller_name != "sessions" %>') + expect(result).to eql('<%- if controller_name != "sessions" %>') + end + + it "handles trailing whitespace trim tag" do + result = subject.format('<% if controller_name != "sessions" -%>') + expect(result).to eql('<% if controller_name != "sessions" -%>') + end + + it "handles both whitespace trim tag" do + result = subject.format('<%- if controller_name != "sessions" -%>') + expect(result).to eql('<%- if controller_name != "sessions" -%>') + end + + it "handles minus unary operator" do + result = subject.format('<% - x * y %>') + expect(result).to eql('<% -x * y %>') + end end end From fd0fd15d3d72cd5831167ca64dee9a979f129f43 Mon Sep 17 00:00:00 2001 From: Kazuki Nishikawa Date: Wed, 24 Dec 2025 17:41:04 +0900 Subject: [PATCH 2/2] format with rufo --- spec/lib/rufo/erb_formatter_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/rufo/erb_formatter_spec.rb b/spec/lib/rufo/erb_formatter_spec.rb index 3820a049..f00ed0ba 100644 --- a/spec/lib/rufo/erb_formatter_spec.rb +++ b/spec/lib/rufo/erb_formatter_spec.rb @@ -116,8 +116,8 @@ end it "handles minus unary operator" do - result = subject.format('<% - x * y %>') - expect(result).to eql('<% -x * y %>') + result = subject.format("<% - x * y %>") + expect(result).to eql("<% -x * y %>") end end end