nebulab/erb-formatter

Format long ERB lines

lcampanari opened this issue ยท 4 comments

Hey, thanks for this gem!

The readme says "attempts to limit length (configurable)". How can I configure that?

I tried running the following case in the command line

def test_format_ruby
assert_equal(
"<div>\n" \
" <%= render MyComponent.new(\n" \
" foo: barbarbarbarbarbarbarbar,\n" \
" bar: bazbazbazbazbazbazbazbaz\n" \
" ) %>\n" \
"</div>\n",
ERB::Formatter.format("<div> <%=render MyComponent.new(foo:barbarbarbarbarbarbarbar,bar:bazbazbazbazbazbazbazbaz)%> </div>"),
)
end

with

echo "<div> <%=render MyComponent.new(foo:barbarbarbarbarbarbarbar,bar:bazbazbazbazbazbazbazbaz, baz:bahbahbahbahbahbahbahbabahbahbahbah, bah: fozfozfozfozfozfozfozfofzofzofzofozfozfozofz)%> </div>" | erb-format --stdin

and the result was

<div>
  <%= render MyComponent.new(foo:barbarbarbarbarbarbarbar,bar:bazbazbazbazbazbazbazbaz, baz:bahbahbahbahbahbahbahbabahbahbahbah, bah: fozfozfozfozfozfozfozfofzofzofzofozfozfozofz) %>
</div>

Is there anything I need to do in order to format long embedded ruby lines?

elia commented

For now it can only be passed when used directly in Ruby (see below), but ideally there should be a CLI flag to set that number.
Happy to review a PR if you want to take up the challenge ๐Ÿ™Œ

https://github.com/nebulab/erb-formatter/blob/main/lib/erb/formatter.rb#L77

NVM, I misread the issue, I think you can try the master version, which should contain a fix for that.
We'll release soon, so if that works just close this issue and wait for the update! Thanks for your patience ๐Ÿ™

cj commented

@elia I seem to be having an issue with 0.4.1 and long lines. (It might be related). I am doing the following bundle exec erb-format % --print-width 120 and the result are:

image

I would have expected the result to be:

image

As the line length of the longest line is only 99.

elia commented

@cj just released v0.4.2, let me know if it doesn't work and we'll reopen ๐Ÿ‘

cj commented

@elia works perfectly, thank you so much!