diff --git a/src/printer.mjs b/src/printer.mjs index cf7388092..066b68f71 100644 --- a/src/printer.mjs +++ b/src/printer.mjs @@ -1297,17 +1297,18 @@ function printClass(path, options, print) { } } + const hasEmptyClassBody = + node.body && node.body.length === 0 && !hasDanglingComments(node); + const printedDeclaration = group([ group(declaration), - shouldPrintHardlineForOpenBrace(options) + shouldPrintHardlineForOpenBrace(options) && !hasEmptyClassBody ? isAnonymousClass ? line : hardline : " ", ]); - const hasEmptyClassBody = - node.body && node.body.length === 0 && !hasDanglingComments(node); const printedBody = [ "{", indent([ @@ -1315,7 +1316,7 @@ function printClass(path, options, print) { printStatements(path, options, print, "body"), ]), printDanglingComments(path, options, true), - isAnonymousClass && hasEmptyClassBody ? softline : hardline, + hasEmptyClassBody ? "" : hardline, "}", ]; @@ -1383,14 +1384,14 @@ function printFunction(path, options, print) { return [...declAttrs, printedDeclaration]; } - const isClosure = node.kind === "closure"; const printedBody = [ "{", indent([hasEmptyBody(path) ? "" : hardline, print("body")]), - isClosure && hasEmptyBody(path) ? "" : hardline, + hasEmptyBody(path) ? "" : hardline, "}", ]; + const isClosure = node.kind === "closure"; if (isClosure) { return [...declAttrs, printedDeclaration, " ", printedBody]; } @@ -1399,7 +1400,9 @@ function printFunction(path, options, print) { return [ ...declAttrs, printedDeclaration, - shouldPrintHardlineForOpenBrace(options) ? hardline : " ", + shouldPrintHardlineForOpenBrace(options) && !hasEmptyBody(path) + ? hardline + : " ", printedBody, ]; } @@ -1415,7 +1418,9 @@ function printFunction(path, options, print) { conditionalGroup([ [ printedDeclaration, - shouldPrintHardlineForOpenBrace(options) ? hardline : " ", + shouldPrintHardlineForOpenBrace(options) && !hasEmptyBody(path) + ? hardline + : " ", printedBody, ], [printedDeclaration, " ", printedBody], diff --git a/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap b/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap index 021fbbbd4..16622e7c1 100644 --- a/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap @@ -181,9 +181,7 @@ final class DomainEventMessage } #[Attr1(Attr1::FOO | Attr1::BAR), Attr2(-20 * 5 + 10)] -class A -{ -} +class A {} class ValueModel { diff --git a/tests/brace-style/__snapshots__/jsfmt.spec.mjs.snap b/tests/brace-style/__snapshots__/jsfmt.spec.mjs.snap index cf6e66b5d..4db4b933b 100644 --- a/tests/brace-style/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/brace-style/__snapshots__/jsfmt.spec.mjs.snap @@ -43,95 +43,65 @@ $class = new class extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryV =====================================output===================================== something->method( $this->more->stuff($this->even->more->things->complicatedMethod()) ); -class A -{ -} +class A {} $someVar = new ReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongClassName(); @@ -1166,12 +1132,8 @@ class FooBar { public $property; public $property2; - public function method() - { - } - public function method2() - { - } + public function method() {} + public function method2() {} } class FooBarFoo @@ -1182,76 +1144,52 @@ class FooBarFoo } } -class ClassName extends ParentClass implements InterfaceClass -{ -} +class ClassName extends ParentClass implements InterfaceClass {} class ClassName extends ParentClass implements - VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 -{ -} + VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 {} class ClassName extends ParentClass implements - VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 -{ -} + VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 {} class ClassName extends VeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 implements - InterfaceClass -{ -} + InterfaceClass {} class ClassName extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 - implements InterfaceClass -{ -} + implements InterfaceClass {} class ClassName extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 - implements VeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 -{ -} + implements VeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 {} class ClassName extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 - implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 -{ -} + implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 {} class ClassName extends ParentClass implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1, VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName2, - VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName3 -{ -} + VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName3 {} class ClassName extends VeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1, VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName2, - VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName3 -{ -} + VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName3 {} class ClassName extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1, VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName2, - VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName3 -{ -} + VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName3 {} class VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFileName1 extends ParentClass - implements InterfaceClass -{ -} + implements InterfaceClass {} class Custom_Plugin_NotificationPlaceholderSource extends - Notification_Manager_DefaultPlaceholderSource -{ -} + Notification_Manager_DefaultPlaceholderSource {} class field extends \\models\\base { @@ -1280,187 +1218,121 @@ class test } } -class EmptyClass -{ -} +class EmptyClass {} class EmptyClassWithComments { /* Comment */ } -class MyClass implements MyOtherClass -{ -} +class MyClass implements MyOtherClass {} -class MyClass implements MyOtherClass, MyOtherClass1, MyOtherClass2 -{ -} +class MyClass implements MyOtherClass, MyOtherClass1, MyOtherClass2 {} class MyClass implements - VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass -{ -} + VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass {} class VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass - implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyOtherClass -{ -} + implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyOtherClass {} class VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass - implements MyOtherClass -{ -} + implements MyOtherClass {} class MyClass implements MyOtherClass, MyOtherClass, MyOtherOtherOtherClass, - MyOtherOtherOtherOtherClass -{ -} + MyOtherOtherOtherOtherClass {} class VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass implements MyOtherClass, MyOtherClass, MyOtherOtherOtherClass, - MyOtherOtherOtherOtherClass -{ -} + MyOtherOtherOtherOtherClass {} -class EmptyClass extends MyOtherClass -{ -} +class EmptyClass extends MyOtherClass {} class EmptyClass extends - VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass -{ -} + VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass {} class VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass - extends EmptyClass -{ -} + extends EmptyClass {} class VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass - extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass -{ -} + extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass {} -class MyClass extends MyOtherClass implements MyI -{ -} +class MyClass extends MyOtherClass implements MyI {} -class MyClass extends MyOtherClass implements MyI, MyII, MyIII -{ -} +class MyClass extends MyOtherClass implements MyI, MyII, MyIII {} class MyClass extends MyOtherClass implements - VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass -{ -} + VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass {} class MyClass extends MyOtherClass implements MyInterface, MyOtherInterface, - MyOtherOtherInterface -{ -} + MyOtherOtherInterface {} class MyClass extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass - implements MyI -{ -} + implements MyI {} class MyClass extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass implements MyI, MyII, - MyIII -{ -} + MyIII {} class MyClass extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass - implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass -{ -} + implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass {} class MyClass extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass implements MyI, MyII, - MyIII -{ -} + MyIII {} -final class BaseClass -{ -} +final class BaseClass {} -abstract class BaseClass -{ -} +abstract class BaseClass {} -final readonly class BaseClass -{ -} +final readonly class BaseClass {} -final readonly class BaseClass -{ -} +final readonly class BaseClass {} -final class BaseClass extends MyOtherClass -{ -} +final class BaseClass extends MyOtherClass {} -abstract class BaseClass extends MyOtherClass -{ -} +abstract class BaseClass extends MyOtherClass {} -final readonly class BaseClass extends MyOtherClass -{ -} +final readonly class BaseClass extends MyOtherClass {} -final readonly class BaseClass extends MyOtherClass -{ -} +final readonly class BaseClass extends MyOtherClass {} -final class BaseClass extends MyOtherVeryVeryVeryVeVeryVeryVeryVeryVeryLongClass -{ -} +final class BaseClass extends + MyOtherVeryVeryVeryVeVeryVeryVeryVeryVeryLongClass {} -abstract class BaseClass extends MyOtherVeryVeryVeryVeVeryVeryVeryVVeryLongClass -{ -} +abstract class BaseClass extends + MyOtherVeryVeryVeryVeVeryVeryVeryVVeryLongClass {} final class BaseClass extends - MyOtherVeryVeryVeryVeVeryVeryVeryVeryVeryLongClass1 -{ -} + MyOtherVeryVeryVeryVeVeryVeryVeryVeryVeryLongClass1 {} abstract class BaseClass extends - MyOtherVeryVeryVeryVeVeryVeryVeryVVeryLongClass1 -{ -} + MyOtherVeryVeryVeryVeVeryVeryVeryVVeryLongClass1 {} final class BaseClass extends MyOtherClass implements MyInterface, MyOtherInterface, - MyOtherOtherInterface -{ -} + MyOtherOtherInterface {} abstract class BaseClass extends MyOtherClass implements MyInterface, MyOtherInterface, - MyOtherOtherInterface -{ -} + MyOtherOtherInterface {} class User { @@ -1483,8 +1355,7 @@ class Promoted public int $a, private float $b, protected string $d - ) { - } + ) {} } readonly class ReadOnlyCls diff --git a/tests/comments/__snapshots__/jsfmt.spec.mjs.snap b/tests/comments/__snapshots__/jsfmt.spec.mjs.snap index b19294f93..a01c42f14 100644 --- a/tests/comments/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/comments/__snapshots__/jsfmt.spec.mjs.snap @@ -943,9 +943,7 @@ class ResponseMethodFailure // Some comment FooBar, // Another comment - BarBaz -{ -} + BarBaz {} // 424 : Method failure class ResponseMethodFailure @@ -955,9 +953,7 @@ class ResponseMethodFailure // Some comment FooBar, // Another comment - BarBaz -{ -} + BarBaz {} // 424 : Method failure class ResponseMethodFailure @@ -967,27 +963,19 @@ class ResponseMethodFailure // Some comment FooBar, // Another comment - BarBaz -{ -} + BarBaz {} // 424 : Method failure class ResponseMethodFailure extends ResponseNotAcceptable implements // Some comment FooBar, // Another comment - BarBaz -{ -} + BarBaz {} -class MyClass -{ -} +class MyClass {} // Comment -class MyClass -{ -} +class MyClass {} class MyClass { @@ -2690,9 +2678,7 @@ foreach ($connections as $sqlite) { * * @return string */ -function test($parameter1, $e) -{ -} +function test($parameter1, $e) {} ================================================================================ `; @@ -2816,9 +2802,7 @@ class Test // body } - function testFunction($arg1, /* inline */ $arg2) - { - } + function testFunction($arg1, /* inline */ $arg2) {} } function testFunction(/* inline */ $arg) @@ -2826,9 +2810,7 @@ function testFunction(/* inline */ $arg) // body } -function testFunction($arg1, /* inline */ $arg2) -{ -} +function testFunction($arg1, /* inline */ $arg2) {} ================================================================================ `; @@ -3433,24 +3415,12 @@ function foo // this is a function =====================================output===================================== */ -class FlowdockFormatter -{ -} +class FlowdockFormatter {} ================================================================================ `; @@ -5455,9 +5403,7 @@ namespace Monolog\\Formatter; * * @author Dominik Liebler */ -class FlowdockFormatter -{ -} +class FlowdockFormatter {} ================================================================================ `; @@ -5495,9 +5441,7 @@ namespace Monolog\\Formatter; * * @author Dominik Liebler */ -class FlowdockFormatter -{ -} +class FlowdockFormatter {} ================================================================================ `; @@ -5531,9 +5475,7 @@ namespace Monolog\\Formatter; * * @author Dominik Liebler */ -class FlowdockFormatter -{ -} +class FlowdockFormatter {} ================================================================================ `; @@ -5567,9 +5509,7 @@ namespace Monolog\\Formatter; // Comment * * @author Dominik Liebler */ -class FlowdockFormatter -{ -} +class FlowdockFormatter {} ================================================================================ `; @@ -5599,9 +5539,7 @@ namespace Monolog\\Formatter; // Comment * * @author Dominik Liebler */ -class FlowdockFormatter -{ -} +class FlowdockFormatter {} ================================================================================ `; @@ -5633,9 +5571,7 @@ namespace Monolog\\Formatter; /* Comment */ * * @author Dominik Liebler */ -class FlowdockFormatter -{ -} +class FlowdockFormatter {} ================================================================================ `; @@ -5671,9 +5607,7 @@ namespace Monolog\\Formatter; /* Comment */ * * @author Dominik Liebler */ -class FlowdockFormatter -{ -} +class FlowdockFormatter {} ================================================================================ `; @@ -5710,9 +5644,7 @@ namespace Monolog\\Formatter; /* Comment */ * * @author Dominik Liebler */ -class FlowdockFormatter -{ -} +class FlowdockFormatter {} ================================================================================ `; @@ -5941,8 +5873,7 @@ $a = new // Comment Foo(); $a = new class// Comment - { -}; + {}; $a = new class { // Comment @@ -6291,36 +6222,28 @@ class MyClass { function foo( /* Comment */ $a, /* Comment */ array /* Comment2 */ $b /* Comment */ = /* Comment */ [] /* Comment */ -) { -} +) {} -function bar(/* Comment */ &$a /* Comment */) -{ -} +function bar(/* Comment */ &$a /* Comment */) {} function baz( /* Comment */ $a, /* Comment */ array /* Comment3 */ &$b /* Comment */ = /* Comment */ [] /* Comment */ -) { -} +) {} class MyClass { public function foo( /* Comment */ $a, /* Comment */ array /* Comment2 */ $b /* Comment */ = /* Comment */ [] /* Comment */ - ) { - } + ) {} - public function bar(/* Comment */ &$a /* Comment */) - { - } + public function bar(/* Comment */ &$a /* Comment */) {} public function baz( /* Comment */ $a, /* Comment */ array /* Comment3 */ &$b /* Comment */ = /* Comment */ [] /* Comment */ - ) { - } + ) {} } ================================================================================ @@ -7104,14 +7027,10 @@ class ImplementingClass } } -trait MyTrait -{ -} +trait MyTrait {} // Comment -trait MyTrait -{ -} +trait MyTrait {} trait MyTrait { diff --git a/tests/enum/__snapshots__/jsfmt.spec.mjs.snap b/tests/enum/__snapshots__/jsfmt.spec.mjs.snap index 03da1a1be..3d304160f 100644 --- a/tests/enum/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/enum/__snapshots__/jsfmt.spec.mjs.snap @@ -122,9 +122,7 @@ enum Suit implements Colorful } } -function paint(Colorful $c) -{ -} +function paint(Colorful $c) {} paint(Suit::Clubs); // Works @@ -140,12 +138,8 @@ enum BackedSuit: string case Spades = 5; } -class Enum -{ -} -class Enum extends Foo -{ -} +class Enum {} +class Enum extends Foo {} ================================================================================ `; diff --git a/tests/functions/__snapshots__/jsfmt.spec.mjs.snap b/tests/functions/__snapshots__/jsfmt.spec.mjs.snap index b9d53cc9f..f7efe0746 100644 --- a/tests/functions/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/functions/__snapshots__/jsfmt.spec.mjs.snap @@ -265,9 +265,7 @@ function &passByReferenceTest() return $a; } -function foo(iterable $iterable = []) -{ -} +function foo(iterable $iterable = []) {} function bar(): iterable { @@ -332,9 +330,7 @@ function the_panel_title( return $title; } -function emptyFunction() -{ -} +function emptyFunction() {} function emptyFunctionWithComment() { /* Comment */ @@ -356,18 +352,10 @@ abstract class AbstractClass class Foo { - public function shortName() - { - } - public function floatShortName(): float - { - } - public function otherShortName() - { - } - public function otherOtherShortName($arg) - { - } + public function shortName() {} + public function floatShortName(): float {} + public function otherShortName() {} + public function otherOtherShortName($arg) {} public function shortNameAndBreak( $title = null, $classes = "panel-title", @@ -375,21 +363,13 @@ class Foo $data_livetext = false, $depth = 0, $index = 0 - ) { - } - public function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName() - { - } - public function floatVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName(): float - { - } - public function otherVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName() - { - } + ) {} + public function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName() {} + public function floatVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName(): float {} + public function otherVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName() {} public function otherOtherVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $arg - ) { - } + ) {} public function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongNameAndBreak( $title = null, $classes = "panel-title", @@ -397,8 +377,7 @@ class Foo $data_livetext = false, $depth = 0, $index = 0 - ) { - } + ) {} } ================================================================================ diff --git a/tests/identifier-and-reference/__snapshots__/jsfmt.spec.mjs.snap b/tests/identifier-and-reference/__snapshots__/jsfmt.spec.mjs.snap index 62f0854bd..05a195ce9 100644 --- a/tests/identifier-and-reference/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/identifier-and-reference/__snapshots__/jsfmt.spec.mjs.snap @@ -238,82 +238,38 @@ Foo::$pArEnT; // Functions -function int(int $var): int -{ -} -function intI(int $var): int -{ -} +function int(int $var): int {} +function intI(int $var): int {} -function float(float $var): float -{ -} -function floatI(float $var): float -{ -} +function float(float $var): float {} +function floatI(float $var): float {} -function bool(bool $var): bool -{ -} -function boolI(bool $var): bool -{ -} +function bool(bool $var): bool {} +function boolI(bool $var): bool {} -function string(string $var): string -{ -} -function stringI(string $var): string -{ -} +function string(string $var): string {} +function stringI(string $var): string {} -function iterable(iterable $var): iterable -{ -} -function iterableI(iterable $var): iterable -{ -} +function iterable(iterable $var): iterable {} +function iterableI(iterable $var): iterable {} -function object(object $var): object -{ -} -function objectI(object $var): object -{ -} +function object(object $var): object {} +function objectI(object $var): object {} -function arrayI(array $var): array -{ -} -function arrayI(array $var): array -{ -} +function arrayI(array $var): array {} +function arrayI(array $var): array {} -function callableI(callable $var): callable -{ -} -function callableII(callable $var): callable -{ -} +function callableI(callable $var): callable {} +function callableII(callable $var): callable {} -function void(): void -{ -} -function voidI(): void -{ -} +function void(): void {} +function voidI(): void {} -function null($var = null) -{ -} -function nullII($var = null) -{ -} +function null($var = null) {} +function nullII($var = null) {} -function something(something $var): something -{ -} -function somethingI(sOmEtHiNg $var): sOmEtHiNg -{ -} +function something(something $var): something {} +function somethingI(sOmEtHiNg $var): sOmEtHiNg {} // Closures @@ -386,96 +342,44 @@ class A return $this; } - public function foo(self $arg) - { - } - public function foo2(self $arg) - { - } - public function foo3(parent $arg) - { - } - public function foo4(parent $arg) - { - } + public function foo(self $arg) {} + public function foo2(self $arg) {} + public function foo3(parent $arg) {} + public function foo4(parent $arg) {} // methods - function int(int $var): int - { - } - function intI(int $var): int - { - } + function int(int $var): int {} + function intI(int $var): int {} - function float(float $var): float - { - } - function floatI(float $var): float - { - } + function float(float $var): float {} + function floatI(float $var): float {} - function bool(bool $var): bool - { - } - function boolI(bool $var): bool - { - } + function bool(bool $var): bool {} + function boolI(bool $var): bool {} - function string(string $var): string - { - } - function stringI(string $var): string - { - } + function string(string $var): string {} + function stringI(string $var): string {} - function iterable(iterable $var): iterable - { - } - function iterableI(iterable $var): iterable - { - } + function iterable(iterable $var): iterable {} + function iterableI(iterable $var): iterable {} - function object(object $var): object - { - } - function objectI(object $var): object - { - } + function object(object $var): object {} + function objectI(object $var): object {} - function arrayI(array $var): array - { - } - function arrayI(array $var): array - { - } + function arrayI(array $var): array {} + function arrayI(array $var): array {} - function callableI(callable $var): callable - { - } - function callableII(callable $var): callable - { - } + function callableI(callable $var): callable {} + function callableII(callable $var): callable {} - function void(): void - { - } - function voidI(): void - { - } + function void(): void {} + function voidI(): void {} - function null($var = null) - { - } - function nullII($var = null) - { - } + function null($var = null) {} + function nullII($var = null) {} - function something(something $var): something - { - } - function somethingI(sOmEtHiNg $var): sOmEtHiNg - { - } + function something(something $var): something {} + function somethingI(sOmEtHiNg $var): sOmEtHiNg {} } // Null diff --git a/tests/interface/__snapshots__/jsfmt.spec.mjs.snap b/tests/interface/__snapshots__/jsfmt.spec.mjs.snap index e58c91616..46b0cf1b7 100644 --- a/tests/interface/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/interface/__snapshots__/jsfmt.spec.mjs.snap @@ -49,54 +49,38 @@ interface test2 extends testInterface public function other($hi); } -interface EmptyInterface -{ -} +interface EmptyInterface {} interface EmptyInterfaceWithComments { /* Comment */ } -interface Foo extends MyClass -{ -} +interface Foo extends MyClass {} -interface Foo extends MyClass, MyOtherClass, OtherClass -{ -} +interface Foo extends MyClass, MyOtherClass, OtherClass {} interface Foo extends - VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName -{ -} + VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName {} interface VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName - extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName -{ -} + extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName {} interface VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName - extends Foo -{ -} + extends Foo {} interface Foo extends MyClass, MyOtherClass, MyOtherOtherOtherClass, - MyVeryVeryVeryLongClassName -{ -} + MyVeryVeryVeryLongClassName {} interface VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName extends MyClass, MyOtherClass, MyOtherOtherOtherClass, - MyVeryVeryVeryLongClassName -{ -} + MyVeryVeryVeryLongClassName {} ================================================================================ `; diff --git a/tests/intersection-types/__snapshots__/jsfmt.spec.mjs.snap b/tests/intersection-types/__snapshots__/jsfmt.spec.mjs.snap index a9ed25d98..b256c0de6 100644 --- a/tests/intersection-types/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/intersection-types/__snapshots__/jsfmt.spec.mjs.snap @@ -20,9 +20,7 @@ function generateSlug(HasTitle&HasId $post) return strtolower($post->getTitle()) . $post->getId(); } -function test(foo|bar &$input) -{ -} +function test(foo|bar &$input) {} ================================================================================ `; diff --git a/tests/method/__snapshots__/jsfmt.spec.mjs.snap b/tests/method/__snapshots__/jsfmt.spec.mjs.snap index ea3783724..2e31fde39 100644 --- a/tests/method/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/method/__snapshots__/jsfmt.spec.mjs.snap @@ -73,9 +73,7 @@ class Foo return "private"; } - public function emptyMethod() - { - } + public function emptyMethod() {} public function emptyMethodWithComment() { @@ -87,9 +85,7 @@ class Foo print "Inside \`aMemberFunc()\`"; } - function bMemberFunc() - { - } + function bMemberFunc() {} } ================================================================================ diff --git a/tests/nowdoc/__snapshots__/jsfmt.spec.mjs.snap b/tests/nowdoc/__snapshots__/jsfmt.spec.mjs.snap index e319852be..6585fb8c3 100644 --- a/tests/nowdoc/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/nowdoc/__snapshots__/jsfmt.spec.mjs.snap @@ -1412,8 +1412,7 @@ string string string EOD - ) { - } + ) {} public function test1( $var, $var = <<<'EOD' @@ -1421,8 +1420,7 @@ string string string EOD - ) { - } + ) {} public function test2( $var = <<<'EOD' string @@ -1431,8 +1429,7 @@ string EOD , $var - ) { - } + ) {} } declare(ticks=1) { @@ -3486,8 +3483,7 @@ class Foo string string EOD - ) { - } + ) {} public function test1( $var, $var = <<<'EOD' @@ -3495,8 +3491,7 @@ class Foo string string EOD - ) { - } + ) {} public function test2( $var = <<<'EOD' string @@ -3505,8 +3500,7 @@ class Foo EOD , $var - ) { - } + ) {} } declare(ticks=1) { diff --git a/tests/parameter/__snapshots__/jsfmt.spec.mjs.snap b/tests/parameter/__snapshots__/jsfmt.spec.mjs.snap index b9219ade6..7ae918b88 100644 --- a/tests/parameter/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/parameter/__snapshots__/jsfmt.spec.mjs.snap @@ -246,8 +246,7 @@ function foo( $arg = 'string string string' -) { -} +) {} function foo( $arg = 'string @@ -256,8 +255,7 @@ string', $arg = 'string string string' -) { -} +) {} function foo( $a, @@ -265,8 +263,7 @@ function foo( string string', $c -) { -} +) {} ================================================================================ `; @@ -322,104 +319,44 @@ class Foo extends ArrayIterator { ================================================================================ diff --git a/tests/traits/__snapshots__/jsfmt.spec.mjs.snap b/tests/traits/__snapshots__/jsfmt.spec.mjs.snap index b6929124b..da9e82484 100644 --- a/tests/traits/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/traits/__snapshots__/jsfmt.spec.mjs.snap @@ -106,9 +106,7 @@ class Partial } } -trait emptyTrait -{ -} +trait emptyTrait {} trait EmptyTraitWithComment { diff --git a/tests/uniontypes/__snapshots__/jsfmt.spec.mjs.snap b/tests/uniontypes/__snapshots__/jsfmt.spec.mjs.snap index 065050c78..acb78e458 100644 --- a/tests/uniontypes/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/uniontypes/__snapshots__/jsfmt.spec.mjs.snap @@ -22,21 +22,15 @@ interface UnionInterface { function do(string|int $in):string|bool; } =====================================output=====================================