Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/prettier/print-abstract-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ export function printAbstractNode(
}

const trailingTriviaDoc = getTrailingTriviaDoc(node);

if (trailingTriviaDoc) {
// prevent extra lines at end of specification
if (
Expand Down
4 changes: 4 additions & 0 deletions src/prettier/util/print-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export function addTrailingTriviaDoc(
): Doc {
if (Array.isArray(doc)) {
if (doc.length === 0) {
doc = [
trailingTriviaDoc,
];

return doc;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/prettier/print-specification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ describe("Print Specification tests", () => {
"§\n",
);
});

test("prettified specification output is as expected for only a comment", async () => {
await testPrettierScenario(
"// Start typing your SDL here... <Ctrl+Space> for completions\n",
"// Start typing your SDL here... <Ctrl+Space> for completions\n",
"// Start typing your SDL here... <Ctrl+Space> for completions\n",
);
});
});
14 changes: 14 additions & 0 deletions tests/prettier/util/print-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,20 @@ describe("Print Utils tests", () => {
ifBreak([line, ""], " "),
["// hello", hardline],
]], hardline], hardline]);

docs = [["class", "A", ["}"], hardline], hardline];
docs = addTrailingTriviaDoc(docs, trailingTriviaDoc);
expect(docs).toEqual([["class", "A", [[
"}",
ifBreak([line, ""], " "),
["// hello", hardline],
]], hardline], hardline]);

docs = [[]];
docs = addTrailingTriviaDoc(docs, trailingTriviaDoc);
expect(docs).toEqual([[
["// hello", hardline],
]]);
});

test("no trivia comment", async () => {
Expand Down