Skip to content

Commit

Permalink
Merge pull request #2997 from quantified-uncertainty/array-extra-comm…
Browse files Browse the repository at this point in the history
…a-bug

Fix incorrect extra commas on empty lists
  • Loading branch information
OAGr committed Jan 23, 2024
2 parents 62bca31 + 2217071 commit da70e66
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-tigers-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@quri/prettier-plugin-squiggle": patch
---

Fix incorrect extra commas on empty lists
13 changes: 10 additions & 3 deletions packages/prettier-plugin/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,16 @@ export function createSquigglePrinter(
case "Array":
return group([
"[",
indent([softline, join([",", line], path.map(print, "elements"))]),
ifBreak(",", ""), // trailing comma
softline,
node.elements.length
? [
indent([
softline,
join([",", line], path.map(print, "elements")),
]),
ifBreak(",", ""), // trailing comma is there's at least one element
softline,
]
: "",
"]",
]);
case "Call":
Expand Down
11 changes: 11 additions & 0 deletions packages/prettier-plugin/test/arrays.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,15 @@ describe("arrays", () => {
]`
);
});

test("don't break empty arrays", async () => {
expect(
await format(
"asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf = []"
)
).toBe(
`asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf = []
`
);
});
});

0 comments on commit da70e66

Please sign in to comment.