Skip to content

Commit

Permalink
Keep line break after with keyword (#94)
Browse files Browse the repository at this point in the history
* Optional line break after 'with' keyword

* 0.4.2

* Bump mo-fmt
  • Loading branch information
rvanasa authored Apr 6, 2023
1 parent c2c9566 commit 0a3fb7c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prettier-plugin-motoko",
"version": "0.4.1",
"version": "0.4.2",
"description": "A code formatter for the Motoko smart contract language.",
"main": "lib/environments/node.js",
"browser": "lib/environments/web.js",
Expand Down
18 changes: 9 additions & 9 deletions packages/mo-fmt/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/mo-fmt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mo-fmt",
"version": "0.4.1",
"version": "0.4.2",
"description": "An easy-to-use Motoko formatter command.",
"main": "src/cli.js",
"bin": {
Expand All @@ -21,7 +21,7 @@
"commander": "^9.4.0",
"fast-glob": "^3.2.11",
"prettier": "^2.7",
"prettier-plugin-motoko": "^0.4.1"
"prettier-plugin-motoko": "^0.4.2"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.2",
Expand Down
3 changes: 3 additions & 0 deletions src/printers/motoko-tt-ast/spaceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ const spaceConfig: SpaceConfig = {
[tokenEquals('-'), '_', 'keep'],
[tokenEquals('^'), '_', 'keep'],

// 'with' keyword
[tokenEquals('with'), '_', 'keep-space'],

// soft-wrapping operators
['_', 'Dot', 'nil'],
// ['_', 'Dot', 'softwrap'],
Expand Down
5 changes: 5 additions & 0 deletions tests/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,9 @@ describe('Motoko formatter', () => {
test('invisible unicode characters', () => {
expect(format('let x\u200b = 123;')).toStrictEqual('let x = 123;\n');
});

test('`with` keyword', () => {
expect(format('{a and b with c = d}')).toStrictEqual('{ a and b with c = d }\n');
expect(format('{a and b with\nc = d}')).toStrictEqual('{\n a and b with\n c = d\n};\n');
});
});

0 comments on commit 0a3fb7c

Please sign in to comment.