Skip to content

Commit

Permalink
Remove trailing comma for multi-line parenthesized expressions (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanasa authored Mar 12, 2023
1 parent f71f53c commit 1d2c9d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/printers/motoko-tt-ast/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ function printTokenTree(
(!isSeparator || isDelim) &&
!hasNestedGroup &&
!shouldKeepSameLine() &&
(groupType !== 'Paren' || results.length > 1) &&
(groupType === 'Unenclosed' || groupType === 'Curly'
? options.semi
: options.trailingComma !== 'none') &&
Expand Down
8 changes: 6 additions & 2 deletions tests/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('Motoko formatter', () => {
expect(format('().0')).toStrictEqual('().0\n');
// expect(format('(\n).0')).toStrictEqual('().0\n');
expect(format('(\n\n\n).0')).toStrictEqual('().0\n');
expect(format('(\na\n).0')).toStrictEqual('(\n a,\n).0;\n');
expect(format('(\na\n).0')).toStrictEqual('(\n a\n).0;\n');
});

// test('cursor position', () => {
Expand Down Expand Up @@ -286,7 +286,7 @@ describe('Motoko formatter', () => {

test('anonymous function line break', () => {
expect(format('(func() {\na\n})')).toStrictEqual(
'(\n func() {\n a;\n },\n);\n',
'(\n func() {\n a;\n }\n);\n',
);
});

Expand Down Expand Up @@ -348,6 +348,10 @@ describe('Motoko formatter', () => {
expect(format("x : [\nT\n]")).toStrictEqual("x : [\n T\n];\n");
});

test('comma-parentheses', () => {
expect(format('if(\nx) { y }')).toStrictEqual('if (\n x\n) { y };\n');
});

// test('generate diff files from compiler tests', () => {
// for (const extension of ['mo', 'did']) {
// let preOutput = '';
Expand Down

0 comments on commit 1d2c9d8

Please sign in to comment.