Repository: prettier/plugin-xml (js)

Issue:
bracketSameLine not working for long blocks
### bracketSameLine

true

### printWidth

120

### tabWidth

4

### xmlWhitespaceSensitivity

ignore

### xmlSelfClosingSpace

true

### singleAttributePerLine

true

### Input XML

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<jcr:root
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
    xmlns:cq="http://www.day.com/jcr/cq/1.0"
    xmlns:jcr="http://www.jcp.org/jcr/1.0"
    xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
    xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:mixinTypes="[mix:referenceable]"
    jcr:primaryType="cq:Page"
    jcr:uuid="57d651a5-3bf6-40e0-b7de-67eba070df0a">
    <articlereference
        jcr:created="2023-01-04T16:23:14.182+01:00"
        jcr:createdBy="admin"
        jcr:lastModified="2023-01-04T16:49:32.585+01:00"
        jcr:lastModifiedBy="admin"
        jcr:primaryType="nt:unstructured"
        sling:resourceType="ey-unified-site/components/up-article-reference"
        defaultItemExpansion="true"
        hideArticleRefLabel="Hide"
        showArticleRefLabel="Show"
        textIsRich="true"
    />
    <articlereference2
        short1="Hide"
        short2="Show"
    />
</jcr:root>
```


### Current output XML

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<jcr:root
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
    xmlns:cq="http://www.day.com/jcr/cq/1.0"
    xmlns:jcr="http://www.jcp.org/jcr/1.0"
    xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
    xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:mixinTypes="[mix:referenceable]"
    jcr:primaryType="cq:Page"
    jcr:uuid="57d651a5-3bf6-40e0-b7de-67eba070df0a">
    <articlereference
        jcr:created="2023-01-04T16:23:14.182+01:00"
        jcr:createdBy="admin"
        jcr:lastModified="2023-01-04T16:49:32.585+01:00"
        jcr:lastModifiedBy="admin"
        jcr:primaryType="nt:unstructured"
        sling:resourceType="ey-unified-site/components/up-article-reference"
        defaultItemExpansion="true"
        hideArticleRefLabel="Hide"
        showArticleRefLabel="Show"
        textIsRich="true"
    />
    <articlereference2
        short1="Hide"
        short2="Show"
    />
</jcr:root>

```


### Expected output XML

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<jcr:root
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
    xmlns:cq="http://www.day.com/jcr/cq/1.0"
    xmlns:jcr="http://www.jcp.org/jcr/1.0"
    xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
    xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:mixinTypes="[mix:referenceable]"
    jcr:primaryType="cq:Page"
    jcr:uuid="57d651a5-3bf6-40e0-b7de-67eba070df0a">
    <articlereference
        jcr:created="2023-01-04T16:23:14.182+01:00"
        jcr:createdBy="admin"
        jcr:lastModified="2023-01-04T16:49:32.585+01:00"
        jcr:lastModifiedBy="admin"
        jcr:primaryType="nt:unstructured"
        sling:resourceType="ey-unified-site/components/up-article-reference"
        defaultItemExpansion="true"
        hideArticleRefLabel="Hide"
        showArticleRefLabel="Show"
        textIsRich="true" />
    <articlereference2
        short1="Hide"
        short2="Show" />
</jcr:root>

```


Pull request:
Fix for #653
Fixes #653

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1f609dc..e25b011 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
 
 ## [Unreleased]
 
+### Changed
+
+- Fixed the behavior of `bracketSameLine` when the attributes on the parent element broke into multiple lines.
+
 ## [2.2.0] - 2022-05-12
 
 ### Added
diff --git a/src/printer.js b/src/printer.js
index ffc6ba5..0366de4 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -365,7 +365,12 @@ function printElement(path, opts, print) {
 
   // Determine the value that will go between the <, name, and attributes
   // of an element and the /> of an element.
-  const space = opts.xmlSelfClosingSpace ? line : softline;
+  let space;
+  if (opts.bracketSameLine) {
+    space = opts.xmlSelfClosingSpace ? " " : "";
+  } else {
+    space = opts.xmlSelfClosingSpace ? line : softline;
+  }
 
   if (SLASH_CLOSE) {
     return group([...parts, space, SLASH_CLOSE[0].image]);


Test patch:
diff --git a/test/__snapshots__/format.test.js.snap b/test/__snapshots__/format.test.js.snap
index dc8a2a8..09902b8 100644
--- a/test/__snapshots__/format.test.js.snap
+++ b/test/__snapshots__/format.test.js.snap
@@ -79,6 +79,10 @@ use {
     even more
     <content />
   </div>
+
+  <div
+    verylongattribute="verylongvalue"
+    anotherverylongattribute="anotherverylongvalue" />
 </svg>
 <!-- bar -->
 "
@@ -163,6 +167,10 @@ use {
     even more
     <content/>
   </div>
+
+  <div
+    verylongattribute="verylongvalue"
+    anotherverylongattribute="anotherverylongvalue"/>
 </svg>
 <!-- bar -->
 "
@@ -240,6 +248,11 @@ use {
     even more
     <content />
   </div>
+
+  <div
+    verylongattribute="verylongvalue"
+    anotherverylongattribute="anotherverylongvalue"
+  />
 </svg>
 <!-- bar -->
 "
@@ -338,6 +351,11 @@ use {
     even more
     <content />
   </div>
+
+  <div
+    verylongattribute="verylongvalue"
+    anotherverylongattribute="anotherverylongvalue"
+  />
 </svg>
 <!-- bar -->
 "
@@ -424,6 +442,11 @@ use {
     even more
     <content/>
   </div>
+
+  <div
+    verylongattribute="verylongvalue"
+    anotherverylongattribute="anotherverylongvalue"
+  />
 </svg>
 <!-- bar -->
 "
@@ -510,6 +533,11 @@ use {
     even more
     <content />
   </div>
+
+  <div
+    verylongattribute="verylongvalue"
+    anotherverylongattribute="anotherverylongvalue"
+  />
 </svg>
 <!-- bar -->
 "
@@ -589,6 +617,11 @@ use {
     even more
     <content />
   </div>
+
+  <div
+    verylongattribute="verylongvalue"
+    anotherverylongattribute="anotherverylongvalue"
+  />
 </svg>
 <!-- bar -->
 "
diff --git a/test/fixture.xml b/test/fixture.xml
index db4416e..2ff3f0f 100644
--- a/test/fixture.xml
+++ b/test/fixture.xml
@@ -61,5 +61,7 @@
     even more
     <content />
   </div>
+
+  <div verylongattribute="verylongvalue" anotherverylongattribute="anotherverylongvalue" />
 </svg>
 <!-- bar -->