Skip to content

Commit

Permalink
0.9.4: Format empty HTML-tags as a group
Browse files Browse the repository at this point in the history
```diff
<three-word-component
  :attribute1
  :attribute2
  :attribute3="value"
->
-</three-word-component>
+></three-word-component>
```
  • Loading branch information
davidwessman committed Jul 1, 2023
1 parent 98227e3 commit 95f29e1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

## [0.9.4] - 2023-07-01

- Inline even more empty HTML-tags

```diff
<three-word-component
:attribute1
:attribute2
:attribute3="value"
->
-</three-word-component>
+></three-word-component>
```

## [0.9.3] - 2023-06-30

- Print empty html-tags on one line if possible
Expand Down
5 changes: 4 additions & 1 deletion lib/syntax_tree/erb/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def visit_block(node)
def visit_html(node)
# Make sure to group the tags together if there is no child nodes.
if node.elements.size == 0
q.group { visit_block(node) }
q.group do
visit(node.opening)
visit(node.closing)
end
else
visit_block(node)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/syntax_tree/erb/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module SyntaxTree
module ERB
VERSION = "0.9.3"
VERSION = "0.9.4"
end
end
8 changes: 6 additions & 2 deletions test/fixture/javascript_frameworks_formatted.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
boolean
:value="['a', 'b']"
:long-variable-name="data.item.javascript.code"
>
</card-header>
></card-header>

<card-body :content="<%= @content %>" @click="doThis">
<template #button-content>
Expand All @@ -16,6 +15,11 @@
</card-body>
</div>

<three-word-component
:allowed-words="['first', 'second', 'third', 'fourth']"
:disallowed-words="['fifth', 'sixth']"
></three-word-component>

<!-- Alpine -->
<div
x-data="{open: false}"
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/javascript_frameworks_unformatted.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@

<card-body :content="<%= @content %>" @click="doThis"><template #button-content>Hello</template></card-body></div>

<three-word-component :allowed-words="['first', 'second', 'third', 'fourth']" :disallowed-words="['fifth', 'sixth']">
</three-word-component>

<!-- Alpine --><div x-data="{open: false}" class="absolute bottom-0" x-transition:enter="transition ease-out" x-transition:leave="transition ease-in">
<button @click="open = true">Expand</button><span x-show="open"><h1>Hello</h1></span></div>

0 comments on commit 95f29e1

Please sign in to comment.