diff --git a/CHANGELOG.md b/CHANGELOG.md index 924e60fc6..31ac64ef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 'The "remainder" field can only be the last field:' inspection now shows location: PR [#1300](https://github.com/tact-lang/tact/pull/1300) - Forbid "remainder" field at the middle of a contract storage: PR [#1301](https://github.com/tact-lang/tact/pull/1301) - Forbid the `override` modifier for functions without the corresponding super-function: PR [#1302](https://github.com/tact-lang/tact/pull/1302) +- Format empty blocks without extra empty line: PR [#1346](https://github.com/tact-lang/tact/pull/1346) ### Docs diff --git a/src/prettyPrinter.ts b/src/prettyPrinter.ts index db8c64c96..acdef52c9 100644 --- a/src/prettyPrinter.ts +++ b/src/prettyPrinter.ts @@ -380,7 +380,9 @@ const createContext = (spaces: number): Context => { const indent = (rows: readonly ContextModel[]) => block(rows).map((f) => (level: number) => f(level + 1)); const braced = (rows: readonly ContextModel[]) => - block([row(`{`), indent(rows), row(`}`)]); + block( + rows.length > 0 ? [row(`{`), indent(rows), row(`}`)] : [row("{ }")], + ); const list = (items: readonly T[], print: Printer) => items.map((node) => print(node)(ctx)); const grouped = ({ @@ -695,7 +697,7 @@ export const ppAstFuncId = (func: A.AstFuncId): string => func.text; // export const ppStatementBlock: Printer = (stmts) => (c) => - c.braced(stmts.length === 0 ? [c.row("")] : c.list(stmts, ppAstStatement)); + c.braced(stmts.length === 0 ? [] : c.list(stmts, ppAstStatement)); export const ppAsmInstructionsBlock: Printer = (instructions) => (c) => diff --git a/src/test/contracts/case-bin-ops.tact b/src/test/contracts/case-bin-ops.tact index 2e4e2cd4d..268f85f25 100644 --- a/src/test/contracts/case-bin-ops.tact +++ b/src/test/contracts/case-bin-ops.tact @@ -3,8 +3,6 @@ contract SampleContract { init() { self.a = (1 + 2 - 3) / 4 % 5 | 255 & 53 ^ 2; - if (1 > 2 || 3 == 0 && (5 - 3) * 10 > 0) { - - } + if (1 > 2 || 3 == 0 && (5 - 3) * 10 > 0) { } } -} \ No newline at end of file +} diff --git a/src/test/contracts/case-message-opcode.tact b/src/test/contracts/case-message-opcode.tact index ea696de45..e1b098195 100644 --- a/src/test/contracts/case-message-opcode.tact +++ b/src/test/contracts/case-message-opcode.tact @@ -30,5 +30,4 @@ message(DEADBEEF + 1) MyMessageWithExprOpcode { a: Int; } -contract TestContract { -} +contract TestContract { } diff --git a/src/test/contracts/case-traits.tact b/src/test/contracts/case-traits.tact index 69d07cb5b..f5f38e6e6 100644 --- a/src/test/contracts/case-traits.tact +++ b/src/test/contracts/case-traits.tact @@ -1,5 +1,4 @@ -@interface("") trait B { -} +@interface("") trait B { } trait C { abstract get fun d(e: String): String; @@ -12,9 +11,7 @@ trait Ownable with B { const someNum: Int = 2; abstract const something: Int; - receive("message") { - - } + receive("message") { } fun requireOwner() { nativeThrowUnless(132, context().sender == self.owner); @@ -35,4 +32,4 @@ trait Ownable with B { self.owner = owner; self.value = 1; } -} \ No newline at end of file +} diff --git a/src/test/contracts/renamer-expected/case-bin-ops.tact b/src/test/contracts/renamer-expected/case-bin-ops.tact index b720ef96f..487e02a76 100644 --- a/src/test/contracts/renamer-expected/case-bin-ops.tact +++ b/src/test/contracts/renamer-expected/case-bin-ops.tact @@ -3,8 +3,6 @@ contract contract_0 { init() { self.a = (1 + 2 - 3) / 4 % 5 | 255 & 53 ^ 2; - if (1 > 2 || 3 == 0 && (5 - 3) * 10 > 0) { - - } + if (1 > 2 || 3 == 0 && (5 - 3) * 10 > 0) { } } } diff --git a/src/test/contracts/renamer-expected/case-message-opcode.tact b/src/test/contracts/renamer-expected/case-message-opcode.tact index 683a72ceb..7a39dd04e 100644 --- a/src/test/contracts/renamer-expected/case-message-opcode.tact +++ b/src/test/contracts/renamer-expected/case-message-opcode.tact @@ -30,5 +30,4 @@ message(constant_def_5 + 1) message_decl_6 { const constant_def_5: Int = 0xdeadbeef; -contract contract_7 { -} +contract contract_7 { } diff --git a/src/test/contracts/renamer-expected/case-traits.tact b/src/test/contracts/renamer-expected/case-traits.tact index 967178b84..5ece52933 100644 --- a/src/test/contracts/renamer-expected/case-traits.tact +++ b/src/test/contracts/renamer-expected/case-traits.tact @@ -1,5 +1,4 @@ -@interface("") trait trait_0 { -} +@interface("") trait trait_0 { } trait trait_1 { abstract get fun function_decl_2(e: String): String; @@ -12,9 +11,7 @@ trait trait_3 with B { const constant_def_4: Int = 2; abstract const constant_decl_5: Int; - receive("message") { - - } + receive("message") { } fun function_def_6() { nativeThrowUnless(132, context().sender == self.owner);