Repository: sveltejs/prettier-plugin-svelte
Pull request #452 (2024-07-21 16:50:04)

chore: run prettier in ci


Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 49ee502..b488932 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -34,3 +34,5 @@ jobs:
               run: npm ci
             - name: Type check
               run: npm run check
+            - name: Lint
+              run: npm run lint
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87f0479..4132e49 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
 # prettier-plugin-svelte changelog
 
+## 3.2.7 (unreleased)
+
+-   (fix) force quote style inside style directives
+-   (fix) preserve commas in array expressions
+-   (fix) Svelte 5: properly determine end of snippet parameters with TS annotations
+
 ## 3.2.6
 
 -   (feat) Svelte 5: never quote single-expression-attributes
diff --git a/package.json b/package.json
index 1ea7e13..a9b482c 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,8 @@
         "build": "rollup -c",
         "check": "tsc --noEmit",
         "check:watch": "tsc --noEmit --watch",
+        "lint": "prettier --check .",
+        "format": "prettier --write .",
         "test": "ava",
         "prepare": "npm run build",
         "prepublishOnly": "npm test"
diff --git a/src/embed.ts b/src/embed.ts
index e739185..c0018fe 100644
--- a/src/embed.ts
+++ b/src/embed.ts
@@ -100,16 +100,16 @@ export function embed(path: FastPath, _options: Options) {
             printSvelteBlockJS('key');
             break;
         case 'SnippetBlock':
-            // We merge the two parts into one expression, which future-proofs this for template TS support
+            // We merge the two parts into one expression to then treat it like a function
             if (node === parent.expression) {
                 parent.expression.end =
                     options.originalText.indexOf(
                         ')',
-                        parent.context?.end ?? // TODO: remove at some point, snippet API changed in .next-..
+                        (parent.parameters?.[parent.parameters.length - 1] as any)?.typeAnnotation
+                            ?.end ??
                             parent.parameters?.[parent.parameters.length - 1]?.end ??
                             parent.expression.end,
                     ) + 1;
-                parent.context = null;
                 parent.parameters = null;
                 node.isJS = true;
                 node.asFunction = true;
diff --git a/src/print/helpers.ts b/src/print/helpers.ts
index 68ee12f..a33130c 100644
--- a/src/print/helpers.ts
+++ b/src/print/helpers.ts
@@ -17,7 +17,7 @@ import {
     SlotTemplateNode,
     StyleNode,
     TitleNode,
-    WindowNode
+    WindowNode,
 } from './nodes';
 import { ParserOptions } from '../options';
 
diff --git a/src/print/index.ts b/src/print/index.ts
index 531da04..c4b81a3 100644
--- a/src/print/index.ts
+++ b/src/print/index.ts
@@ -1206,7 +1206,16 @@ function _expandNode(node: any, parent?: any): string {
     switch (node.type) {
         case 'ArrayExpression':
         case 'ArrayPattern':
-            return ' [' + node.elements.map(_expandNode).join(',').slice(1) + ']';
+            return (
+                ' [' +
+                node.elements
+                    // handle null specifically here; else it would become the empty string, but that would mean
+                    // fewer elements in the array, which would change the meaning of the array
+                    .map((el: any) => (el === null ? ' ' : _expandNode(el)))
+                    .join(',')
+                    .slice(1) +
+                ']'
+            );
         case 'AssignmentPattern':
             return _expandNode(node.left) + ' =' + _expandNode(node.right);
         case 'Identifier':
diff --git a/src/print/node-helpers.ts b/src/print/node-helpers.ts
index abf1cb5..7c0e92f 100644
--- a/src/print/node-helpers.ts
+++ b/src/print/node-helpers.ts
@@ -533,7 +533,7 @@ export function isInsideQuotedAttribute(path: FastPath, options: ParserOptions):
 
     return stack.some(
         (node) =>
-            node.type === 'Attribute' &&
+            (node.type === 'Attribute' || node.type === 'StyleDirective') &&
             (!isLoneMustacheTag(node.value) ||
                 (options.svelteStrictMode && !options._svelte_is5Plus)),
     );
diff --git a/wallaby.js b/wallaby.js
index 43a34ab..fe8d569 100644
--- a/wallaby.js
+++ b/wallaby.js
@@ -1,4 +1,4 @@
-module.exports = function(w) {
+module.exports = function (w) {
     return {
         files: ['src/**/*.ts', 'test/**/*.html'],
         tests: ['test/**/*.ts'],


Test patch:
diff --git a/test/formatting/samples/syntax-error/options.json b/test/formatting/samples/syntax-error/options.json
index da3820b..b379964 100644
--- a/test/formatting/samples/syntax-error/options.json
+++ b/test/formatting/samples/syntax-error/options.json
@@ -1,3 +1,3 @@
 {
-  "expectSyntaxErrors": true
-}
\ No newline at end of file
+    "expectSyntaxErrors": true
+}
diff --git a/test/printer/samples/allow-shorthand-false.options.json b/test/printer/samples/allow-shorthand-false.options.json
index 1b6ce29..e495e72 100644
--- a/test/printer/samples/allow-shorthand-false.options.json
+++ b/test/printer/samples/allow-shorthand-false.options.json
@@ -1,3 +1,3 @@
 {
-	"svelteAllowShorthand": false
-}
\ No newline at end of file
+    "svelteAllowShorthand": false
+}
diff --git a/test/printer/samples/allow-shorthand-true.options.json b/test/printer/samples/allow-shorthand-true.options.json
index 1672426..29935c6 100644
--- a/test/printer/samples/allow-shorthand-true.options.json
+++ b/test/printer/samples/allow-shorthand-true.options.json
@@ -1,3 +1,3 @@
 {
-	"svelteAllowShorthand": true
-}
\ No newline at end of file
+    "svelteAllowShorthand": true
+}
diff --git a/test/printer/samples/attributes-nested-quotes.html b/test/printer/samples/attributes-nested-quotes.html
new file mode 100644
index 0000000..0405874
--- /dev/null
+++ b/test/printer/samples/attributes-nested-quotes.html
@@ -0,0 +1,3 @@
+<div style:transform="translateX({condition ? '10%' : '20%'})"></div>
+<div class="my-class {condition ? 'a' : 'b'}"></div>
+<Component class="my-class {condition ? 'a' : 'b'}" />
diff --git a/test/printer/samples/each-block-destructured.html b/test/printer/samples/each-block-destructured.html
index 3edd543..8f6af54 100644
--- a/test/printer/samples/each-block-destructured.html
+++ b/test/printer/samples/each-block-destructured.html
@@ -1,3 +1,7 @@
 {#each animals as [key, value]}
     <p>{key}: {value}</p>
 {/each}
+
+{#each animals as [, value]}
+    <p>{value}</p>
+{/each}
diff --git a/test/printer/samples/snippet-ts.html.skip b/test/printer/samples/snippet-ts.html.skip
new file mode 100644
index 0000000..2559ea1
--- /dev/null
+++ b/test/printer/samples/snippet-ts.html.skip
@@ -0,0 +1,14 @@
+<script lang="ts">
+</script>
+
+{#snippet test1(arg: string)}
+    foo
+{/snippet}
+
+{#snippet test2(arg: (typeof obj)["key"])}
+    foo
+{/snippet}
+
+{#snippet test3({ onselect }: { onselect: (value: string) => void })}
+    foo
+{/snippet}