Skip to content

Commit

Permalink
fix instability in formatting AO headers with no arguments (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot authored Jun 8, 2024
1 parent 13e1fb3 commit 531d248
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/formatter/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export function printHeader(
} = parseResult;
/* eslint-enable prefer-const */

const multiline = type === 'multi-line' && (params.length > 0 || optionalParams.length > 0);

const result = new LineBuilder(indent);
if (type === 'multi-line') {
if (multiline) {
result.firstLineIsPartial = false;
}
if (wrappingTag !== null) {
Expand All @@ -60,7 +62,7 @@ export function printHeader(
returnType === null
) {
// do not print a parameter list
} else if (type === 'single-line') {
} else if (!multiline) {
result.appendText(' ' + printSimpleParamList(params, optionalParams));
} else {
result.appendText(' (');
Expand All @@ -80,7 +82,7 @@ export function printHeader(
if (wrappingTag !== null) {
result.appendText(`</${wrappingTag}>`);
}
if (type === 'multi-line') {
if (multiline) {
result.linebreak();
}

Expand Down
24 changes: 24 additions & 0 deletions test/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,30 @@ describe('equation formatting', () => {
});

describe('structured header formatting', () => {
it('multiline with no arguments', async () => {
await assertDocFormatsAs(
`
<emu-clause>
<h1>
Foo (
): ~empty~
</h1>
<dl class="header">
</dl>
</emu-clause>
`,
dedentKeepingTrailingNewline`
<emu-clause>
<h1>Foo ( ): ~empty~</h1>
<dl class="header">
</dl>
</emu-clause>
`,
);
});

it('whitespace in inline style', async () => {
await assertDocFormatsAs(
`
Expand Down

0 comments on commit 531d248

Please sign in to comment.