Skip to content

Commit

Permalink
Use trailing commas
Browse files Browse the repository at this point in the history
Reduce the roundtrip time for adding a line to a list of arguments or
reordering them and discovering about the missing comma after a refresh
of the browser.
  • Loading branch information
elia committed Dec 1, 2023
1 parent a3e56c1 commit 53ea630
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/erb/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'erb/formatter/version'

require 'syntax_tree'
require 'syntax_tree/plugin/trailing_comma'

class ERB::Formatter
module SyntaxTreeCommandPatch
Expand Down
2 changes: 1 addition & 1 deletion test/erb/test_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_format_ruby
"<div>\n" \
" <%= render MyComponent.new(\n" \
" foo: barbarbarbarbarbarbarbar,\n" \
" bar: bazbazbazbazbazbazbazbaz\n" \
" bar: bazbazbazbazbazbazbazbaz,\n" \
" ) %>\n" \
"</div>\n",
ERB::Formatter.format("<div> <%=render MyComponent.new(foo:barbarbarbarbarbarbarbar,bar:bazbazbazbazbazbazbazbaz)%> </div>"),
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/complex_case_when.html.expected.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<% else %>
<% Rails.logger.error.report(
StandardError.new(
"No human readable name found for payment method #{payment_method.class}"
)
"No human readable name found for payment method #{payment_method.class}",
),
) %>
<% end %>
<% else %>
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/formatted-2.html.expected.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{ greeting: "Hello from react-rails." },
{ greeting: "Hello from react-rails." },
{ greeting: "Hello from react-rails." },
{ greeting: "Hello from react-rails." }
{ greeting: "Hello from react-rails." },
) %>

</div>
6 changes: 3 additions & 3 deletions test/fixtures/long_deep_nested-2.html.expected.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
"HelloWorld",
{
greeting:
"Hello from react-rails react-rails react-rails react-rails react-rails react-rails react-rails."
"Hello from react-rails react-rails react-rails react-rails react-rails react-rails react-rails.",
},
{
greeting:
"Hello from react-rails react-rails react-rails react-rails react-rails react-rails react-rails."
"Hello from react-rails react-rails react-rails react-rails react-rails react-rails react-rails.",
},
{ greeting: "Hello from react-rails." },
{ greeting: "Hello from react-rails." }
{ greeting: "Hello from react-rails." },
) %>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/trailing_comma.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= render component("ui/table").new(
id: "option-types-list",
data: {
rows: @option_types,url: ->(option_type) { edit_admin_option_type_path(option_type) },columns: columns,batch_actions: batch_actions,
},
) %>
9 changes: 9 additions & 0 deletions test/fixtures/trailing_comma.html.expected.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= render component("ui/table").new(
id: "option-types-list",
data: {
rows: @option_types,
url: ->(option_type) { edit_admin_option_type_path(option_type) },
columns: columns,
batch_actions: batch_actions,
},
) %>

0 comments on commit 53ea630

Please sign in to comment.