Repository: sveltejs/prettier-plugin-svelte (ts)

Issue:
Whitespace sensitivity is not ignored with Svelte components
It was indirectly implied in #245 that setting `htmlWhitespaceSensitivity` to `"ignore"` would be respected when formatting Svelte components. However, that doesn't seem to be the case. Please see the following example.

Input:

```jsx
<p><ExternalLink href="https://www.buymeacoffee.com">buy me a coffee</ExternalLink>!</p>
```

Output with `htmlWhitespaceSensitivity: "ignore"`:

```jsx
<p>
    <ExternalLink href="https://www.buymeacoffee.com"
        >buy me a coffee</ExternalLink
    >!
</p>
```

I believe the expected output with `htmlWhitespaceSensitivity: "ignore"` should be:

```jsx
<p>
    <ExternalLink href="https://www.buymeacoffee.com">
        buy me a coffee
    </ExternalLink>!
</p>
```

As far as I can tell, this appears to be a bug as it only occurs with Svelte components. Standard HTML elements seem to be treated correctly. For example, the [`all-elements-ignore-whitespace` test](https://github.com/sveltejs/prettier-plugin-svelte/tree/master/test/formatting/samples/all-elements-ignore-whitespace) demonstrates the correct behavior with `<span>` elements but not Svelte components.

Pull request description:
(fix) ignore whitespace sensitivity with Svelte components (#281)
This change fixes #281 and it seems like the right thing to do. I've also added an additional test for this issue to catch any regressions.

I haven't extensively walked through the code base to check if this might have some unintentional impact. However, all of the tests do appear to pass.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 256cebd..6dc34a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # prettier-plugin-svelte changelog
 
+## 2.6.1 (Unreleased)
+
+* (fix) respect whitespace "ignore" setting for components ([#281](https://github.com/sveltejs/prettier-plugin-svelte/issues/281)) 
+
 ## 2.6.0
 
 * (feat) Support `{@const}` tag ([#272](https://github.com/sveltejs/prettier-plugin-svelte/issues/272))
diff --git a/src/print/node-helpers.ts b/src/print/node-helpers.ts
index a4d9f96..d3d644c 100644
--- a/src/print/node-helpers.ts
+++ b/src/print/node-helpers.ts
@@ -396,6 +396,10 @@ export function shouldHugStart(
         return true;
     }
 
+    if (options.htmlWhitespaceSensitivity === 'ignore') {
+        return false;
+    }
+
     const firstChild = children[0];
     return !isTextNodeStartingWithWhitespace(firstChild);
 }
@@ -426,6 +430,10 @@ export function shouldHugEnd(
         return true;
     }
 
+    if (options.htmlWhitespaceSensitivity === 'ignore') {
+        return false;
+    }
+
     const lastChild = children[children.length - 1];
     return !isTextNodeEndingWithWhitespace(lastChild);
 }


Test patch:
diff --git a/test/formatting/samples/component-ignore-whitespace/input.html b/test/formatting/samples/component-ignore-whitespace/input.html
new file mode 100644
index 0000000..b376114
--- /dev/null
+++ b/test/formatting/samples/component-ignore-whitespace/input.html
@@ -0,0 +1,5 @@
+<p><ExternalLink href="https://www.buymeacoffee.com">buy</ExternalLink>!</p>
+
+<p><ExternalLink href="https://www.buymeacoffee.com">buy me a</ExternalLink>!</p>
+
+<p><ExternalLink href="https://www.buymeacoffee.com">buy me a coffee</ExternalLink>!</p>
diff --git a/test/formatting/samples/component-ignore-whitespace/options.json b/test/formatting/samples/component-ignore-whitespace/options.json
new file mode 100644
index 0000000..e3e1f3e
--- /dev/null
+++ b/test/formatting/samples/component-ignore-whitespace/options.json
@@ -0,0 +1,3 @@
+{
+    "htmlWhitespaceSensitivity": "ignore"
+}
diff --git a/test/formatting/samples/component-ignore-whitespace/output.html b/test/formatting/samples/component-ignore-whitespace/output.html
new file mode 100644
index 0000000..caf6f4d
--- /dev/null
+++ b/test/formatting/samples/component-ignore-whitespace/output.html
@@ -0,0 +1,11 @@
+<p><ExternalLink href="https://www.buymeacoffee.com">buy</ExternalLink>!</p>
+
+<p>
+    <ExternalLink href="https://www.buymeacoffee.com">buy me a</ExternalLink>!
+</p>
+
+<p>
+    <ExternalLink href="https://www.buymeacoffee.com">
+        buy me a coffee
+    </ExternalLink>!
+</p>