language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
hhvm/hphp/hack/test/hackfmt/difftests/fixme_3.diff
diff --git a/fixme.php b/fixme.php --- a/fixme.php +++ b/fixme.php @@ -8,2 +8,2 @@ - /* HH_FIXME[4110] Some comment */ - return vec[2, + /* HH_FIXME[4110] */ + return vec[1,
hhvm/hphp/hack/test/hackfmt/difftests/fixme_4.diff
diff --git a/fixme.php b/fixme.php --- a/fixme.php +++ b/fixme.php @@ -8,3 +8,3 @@ - /* HH_FIXME[4110] Some comment */ - return vec[2, - 1, + /* HH_FIXME[4110] */ + return vec[1, + 2,
hhvm/hphp/hack/test/hackfmt/difftests/fixme_5.diff
diff --git a/fixme.php b/fixme.php --- a/fixme.php +++ b/fixme.php @@ -8,4 +8,4 @@ - /* HH_FIXME[4110] Some comment */ - return vec[2, - 1, - 5]; + /* HH_FIXME[4110] */ + return vec[1, + 2, + 3];
hhvm/hphp/hack/test/hackfmt/difftests/fixme_6.diff
diff --git a/fixme.php b/fixme.php --- a/fixme.php +++ b/fixme.php @@ -9,1 +9,1 @@ - return vec[2, + return vec[1,
hhvm/hphp/hack/test/hackfmt/difftests/heredoc_strings.diff
diff --git a/heredoc_strings.php b/heredoc_strings.php --- a/heredoc_strings.php +++ b/heredoc_strings.php @@ -4,6 +4,8 @@ $title2 = "FISH?"; $silverstein = <<<EOF +{$title1} + I tripped on my shoelace And I fell up-- Up to the roof tops, @@ -17,6 +19,8 @@ I got sick to my stomach And I threw down. +{$title2} + The little fish eats the tiny fish, The big fish eats the little fish-- So only the biggest fish gets fat.
hhvm/hphp/hack/test/hackfmt/difftests/join_to_untouched_line.diff
diff --git a/fibonacci.php b/fibonacci.php --- a/fibonacci.php +++ b/fibonacci.php @@ -4,6 +4,6 @@ $arr = array(0, 1); for ($i = 2; $i <= $pos; ++$i) $arr[$i] = - $arr[$i-1] + $arr[$i-2]; + $arr[ $i - 1 ] + $arr[ $i - 2 ]; return $arr[$pos]; }
hhvm/hphp/hack/test/hackfmt/difftests/join_to_untouched_line_with_comment.diff
diff --git a/line_joining.php b/line_joining.php --- a/line_joining.php +++ b/line_joining.php @@ -2,4 +2,4 @@ // These lines will be joined: $foo = - 'bar'; + 'baz';
hhvm/hphp/hack/test/hackfmt/difftests/method_add.diff
diff --git a/Point.php b/Point.php --- a/Point.php +++ b/Point.php @@ -23,6 +23,11 @@ $this->y += $y; } + public function magnitude() + { + return sqrt($this->x ** 2 + $this->y ** 2); + } + public function __toString() { return '(' . $this->x . ',' . $this->y . ')';
hhvm/hphp/hack/test/hackfmt/difftests/method_remove.diff
diff --git a/Point.php b/Point.php --- a/Point.php +++ b/Point.php @@ -28,14 +28,6 @@ return sqrt($this->x ** 2 + $this->y ** 2); } - public function distance(Point $p) - { - return sqrt( - ($this->x - $p->x) ** 2 + - ($this->y - $p->y) ** 2 - ); - } - public function __toString() { return '(' . $this->x . ',' . $this->y . ')';
hhvm/hphp/hack/test/hackfmt/difftests/multifile.diff
diff --git a/balanced_brackets.php b/balanced_brackets.php --- a/balanced_brackets.php +++ b/balanced_brackets.php @@ -3,16 +3,16 @@ // https://rosettacode.org/wiki/Balanced_brackets#PHP function isbalanced(string $s): bool { - $balance = 0; + $bal = 0; for ($i = 0; $i < strlen($s); ++$i) { $ch = substr($s, $i, 1); if ($ch == '[') { - $balance++; + $bal++; } elseif ($ch == ']') { - $balance--; + $bal--; } - if ($balance < 0) + if ($bal < 0) return false; } - return ($balance == 0); + return ($bal == 0); } diff --git a/fibonacci.php b/fibonacci.php --- a/fibonacci.php +++ b/fibonacci.php @@ -1,9 +1,9 @@ <?hh // strict function fibonacci($pos){ - $a = array(0, 1); + $arr = array(0, 1); for ($i = 2; $i <= $pos; ++$i) - $a[$i] = - $a[$i-1] + $a[$i-2]; - return $a[$pos]; + $arr[$i] = + $arr[$i-1] + $arr[$i-2]; + return $arr[$pos]; }
hhvm/hphp/hack/test/hackfmt/difftests/parse_error.diff
diff --git a/parse_error.php b/parse_error.php --- a/parse_error.php +++ b/parse_error.php @@ -1,5 +1,5 @@ <?hh // strict function square(int $x): int { - return $x*$x; + return $x*$x } diff --git a/fibonacci.php b/fibonacci.php --- a/fibonacci.php +++ b/fibonacci.php @@ -1,9 +1,9 @@ <?hh // strict function fibonacci($pos){ - $a = array(0, 1); + $arr = array(0, 1); for ($i = 2; $i <= $pos; ++$i) - $a[$i] = - $a[$i-1] + $a[$i-2]; - return $a[$pos]; + $arr[$i] = + $arr[$i-1] + $arr[$i-2]; + return $arr[$pos]; }
hhvm/hphp/hack/test/hackfmt/difftests/remove_method_statements.diff
diff --git a/Point.php b/Point.php --- a/Point.php +++ b/Point.php @@ -4,20 +4,17 @@ { private $x; // Cartesian x-coordinate private $y; // Cartesian y-coordinate - private $z; // Cartesian z-coordinate public function __construct($x = 0, $y = 0) { $this->x = $x; $this->y = $y; - $this->z = 0; } public function move($x, $y) { $this->x = $x; $this->y = $y; - $this->z = $0; } public function translate($x, $y)
hhvm/hphp/hack/test/hackfmt/difftests/renamed_query.diff
diff --git a/renamed_query.php b/renamed_query.php --- a/renamed_query.php +++ b/renamed_query.php @@ -1,7 +1,7 @@ <?hh $matches = await - SomeQueriableEntityWithAnExtraordinarilyLongIdentifier::entityQuery( + SomeQueriableEntityWithALongButNowRenamedIdentifier::entityQuery( $context_object, $id, )
hhvm/hphp/hack/test/hackfmt/difftests/trailing_comma_at_interval_start.diff
diff --git a/query.php b/query.php --- a/query.php +++ b/query.php @@ -4,7 +4,11 @@ await SomeQueriableEntityWithAnExtraordinarilyLongIdentifier::entityQuery( $context_object, $id, - )->before(time()) - ->orderedSlice(10, Ordering::newest()); + ) + ->queryEdges() + ->whereTime(P::lessThanOrEquals((int)time())) + ->orderByTimeDesc() + ->take(10) + |> gen_new_array($$); return $matches;
hhvm/hphp/hack/test/hackfmt/difftests/unindented_chain_line.diff
diff --git a/chaining.php b/chaining.php --- a/chaining.php +++ b/chaining.php @@ -19,7 +19,7 @@ $my_object ?->getASubObjectFromMyObject() ->getSomeOtherObject() +->addedUnindented ?->field ->subField;
hhvm/hphp/hack/test/hackfmt/difftests/var_rename.diff
diff --git a/fibonacci.php b/fibonacci.php --- a/fibonacci.php +++ b/fibonacci.php @@ -1,9 +1,9 @@ <?hh // strict function fibonacci($pos){ - $a = array(0, 1); + $arr = array(0, 1); for ($i = 2; $i <= $pos; ++$i) - $a[$i] = - $a[$i-1] + $a[$i-2]; - return $a[$pos]; + $arr[$i] = + $arr[$i-1] + $arr[$i-2]; + return $arr[$pos]; }
PHP
hhvm/hphp/hack/test/hackfmt/difftests/root/balanced_brackets.php
<?hh // strict // https://rosettacode.org/wiki/Balanced_brackets#PHP function isbalanced(string $s): bool { $bal = 0; for ($i = 0; $i < strlen($s); ++$i) { $ch = substr($s, $i, 1); if ($ch == '[') { $bal++; } else if ($ch == ']') { $bal--; } if ($bal < 0) return false; } return ($bal == 0); }
PHP
hhvm/hphp/hack/test/hackfmt/difftests/root/chaining.php
<?hh // strict function member_and_function_call_chain(MyObject $my_object): void { $my_object ->getASubObjectFromMyObject() ->getSomeOtherObject() ->directObject ?->field ->subField ?->method(); $my_object?->getASubObjectFromMyObject ->getSomeOtherObject() ->changed ?->field ->subField ->method(); $my_object ?->getASubObjectFromMyObject() ->getSomeOtherObject() ->addedUnindented ?->field ->subField; $my_object ?->getASubObjectFromMyObject ->getSomeOtherObject() ->directObject ?->field; }
PHP
hhvm/hphp/hack/test/hackfmt/difftests/root/fibonacci.php
<?hh // strict function fibonacci($pos){ $arr = varray[0, 1]; for ($i = 2; $i <= $pos; ++$i) $arr[$i] = $arr[$i-1] + $arr[$i-2]; return $arr[$pos]; }
PHP
hhvm/hphp/hack/test/hackfmt/difftests/root/fixme.php
<?hh // strict final class Foo { public function bar( vec<int> $ints, ): vec<int> { $ints = Vec\shuffle($ints); /* HH_FIXME[4110] */ return vec[1, 2, 3]; } }
PHP
hhvm/hphp/hack/test/hackfmt/difftests/root/heredoc_strings.php
<?hh $title1 = "FALLING UP"; $title2 = "FISH?"; $silverstein = <<<EOF {$title1} I tripped on my shoelace And I fell up-- Up to the roof tops, Up over the town, Up past the tree tops, Up over the mountains, Up where the colors Blend into the sounds. But it got me so dizzy When I looked around, I got sick to my stomach And I threw down. {$title2} The little fish eats the tiny fish, The big fish eats the little fish-- So only the biggest fish gets fat. Do you know any folks like that? EOF; $foo = 'bar';
PHP
hhvm/hphp/hack/test/hackfmt/difftests/root/Point.php
<?hh // strict class Point { private $x; // Cartesian x-coordinate private $y; // Cartesian y-coordinate public function __construct($x = 0, $y = 0) { $this->x = $x; $this->y = $y; } public function move($x, $y) { $this->x = $x; $this->y = $y; } public function translate($x, $y) { $this->x += $x; $this->y += $y; } public function magnitude() { return sqrt($this->x ** 2 + $this->y ** 2); } public function __toString() { return '(' . $this->x . ',' . $this->y . ')'; } }
PHP
hhvm/hphp/hack/test/hackfmt/difftests/root/query.php
<?hh $matches = await SomeQueriableEntityWithAnExtraordinarilyLongIdentifier::entityQuery( $context_object, $id, ) ->queryEdges() ->whereTime(P::lessThanOrEquals((int)time())) ->orderByTimeDesc() ->take(10) |> gen_new_array($$); return $matches;
PHP
hhvm/hphp/hack/test/hackfmt/difftests/root/renamed_query.php
<?hh $matches = await SomeQueriableEntityWithALongButNowRenamedIdentifier::entityQuery( $context_object, $id, ) ->queryEdges() ->whereTime(P::lessThanOrEquals((int)time())) ->orderByTimeDesc() ->take(10) |> gen_new_array($$); return $matches;
PHP
hhvm/hphp/hack/test/hackfmt/difftests/root/sum.php
<?hh // strict /** * Returns the sum of the two arguments. * * Equivalent to $a + $b. */ function sum(int $a, int $b) { return $a + $b; }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/at_char_blank_lines.php
<?hh function fibonacci($pos){ $arr = varray[0, 1]; for ($i = 2; $i <= $pos; ++$i) $arr[$i] = $arr[$i-1] + $arr[$i-2]; return $arr[$pos]; }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/at_char_compound_statement.php
<?hh function foo(int $x) { takeSomeAction ( ); { // UNSAFE_BLOCK takesString ( $x ); } takeOtherAction ( ); }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/at_char_method.php
<?hh class Foo { public function foo( int $bar, ): int { return $bar; } public function notFormatted() { return 42; } }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/at_char_semicolon.php
<?hh function fibonacci($pos){ $arr = varray[0, 1]; for ($i = 2; $i <= $pos; ++$i) $arr[$i] = $arr[$i-1] + $arr[$i-2]; return $arr[$pos]; }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/binary_expression_range_formatting.php
<?hh abstract final class FooClass { public static function getFirstPotentialBar() { $potentialBars = BarManager::getPotentialBarsForType($type) |> Vec\filter( $$, $index ==> self::isPotentialBar($index, $someOtherLongArgument) ) |> Vec\map( $$, ( Baz::TSomeTypeWithALongIdentifier $index, ): ?SomePotentialBarType ==> self::getPotentialBar( $index, $argumentTwo, $argumentThree, $argumentFour, ), ) |> Vec\filter_nulls($$) |> Vec\sort( $$, (SomePotentialBarType $a, SomePotentialBarType $b): int ==> self::comparePotentialBars($a, $b), ); return C\first($potentialBars); } }
hhvm/hphp/hack/test/hackfmt/range_tests/dune
(rule (alias verify_range) (deps %{exe:../../../src/hackfmt.exe} %{project_root}/hack/test/verify.py %{project_root}/hack/test/review.sh (glob_files %{project_root}/hack/test/hackfmt/range_tests/*.flags) (glob_files %{project_root}/hack/test/hackfmt/range_tests/*.php) (glob_files %{project_root}/hack/test/hackfmt/range_tests/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/hackfmt/range_tests --program %{exe:../../../src/hackfmt.exe} --flags --test))) (alias (name runtest) (deps (alias verify_range)))
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/heredoc_partial_formatting.php
<?hh $title1 = "FALLING UP"; $title2 = "FISH?"; $silverstein = <<<EOF {$title1} I tripped on my shoelace And I fell up-- Up to the roof tops, Up over the town, Up past the tree tops, Up over the mountains, Up where the colors Blend into the sounds. But it got me so dizzy When I looked around, I got sick to my stomach And I threw down. {$title2} The little fish eats the tiny fish, The big fish eats the little fish-- So only the biggest fish gets fat. Do you know any folks like that? EOF; $foo = 'bar';
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/invalid_split_outside_range.php
<?hh function f() { return vec[ foo($a ==> { return $a; }, $b), bar($x_______________________________________________________________________), ]; }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/line_range_hh_fixme_1.php
<?hh function foo() { /* HH_FIXME[1000] */ return vec[100, 200, 300, 400, 500, 600, 700, 800, 900]; }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/line_range_hh_fixme_2.php
<?hh // strict function foo(): vec<int> { return vec[ 100, 200, 300, /* HH_FIXME[4110] */ 400, '5', 600, 700, 800, 900, ]; }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/line_range_hh_fixme_3.php
<?hh // strict function foo(): vec<int> { return vec[ /* HH_FIXME[4110] 2 */ 100, '2', 300, 400, 500, 600, /* HH_FIXME[4110] 8 */ 700, '8', 900, ]; }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/line_range_ignore_format.php
<?hh class C { public function foo(): void { f(() ==> { // hackfmt-ignore - this should be left as-is vec[ 100, 200, 300, 400, 500, 600, 700, 800, 900, 100, 200, 300, 400, 500, 600, 700, 800, 900, 100, 200, 300, 400, 500, 600, 700, 800, 900, ]; }); } }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/PartialFormattingTest1.php
<?hh // Copyright 2004-present Facebook. All Rights Reserved. /** * Static functions supporting nothing */ abstract final class PartialFormattingTest { // Comment1 // Comment2 public static async function genMaybeValidateID( ?int $id = null, bool $validate = false, ): Awaitable<?int> { $nonsensical_maplike_array = darray[ "A Very Long Key Value For This Map" => "Here's a value of an appropriate length" ]; if (false) { /** * TODO: Do something * MultilineComment1 * * MultilineComment1-2 */ $errors = varray[]; $create_exception = null; } // Comment 3 // Comment 4 // Comment 5 return $id; } }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/PartialFormattingTest2.php
<?hh // Copyright 2004-present Facebook. All Rights Reserved. /** * Static functions supporting nothing */ abstract final class PartialFormattingTest { // Comment1 // Comment2 public static async function genMaybeValidateID( ?int $id = null, bool $validate = false, ): Awaitable<?int> { $nonsensical_maplike_array = darray[ "A Very Long Key Value For This Map" => "Here's a value of an appropriate length" ]; if (false) { /** * TODO: Do something * MultilineComment1 * * MultilineComment1-2 */ $errors = varray[]; $create_exception = null; } // Comment 3 // Comment 4 // Comment 5 return $id; } }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/PartialFormattingTest3.php
<?hh // Copyright 2004-present Facebook. All Rights Reserved. /** * Static functions supporting nothing */ abstract final class PartialFormattingTest { // Comment1 // Comment2 public static async function genMaybeValidateID( ?int $id = null, bool $validate = false, ): Awaitable<?int> { $nonsensical_maplike_array = darray[ "A Very Long Key Value For This Map" => "Here's a value of an appropriate length" ]; if (false) { /** * TODO: Do something * MultilineComment1 * * MultilineComment1-2 */ $errors = varray[]; $create_exception = null; } // Comment 3 // Comment 4 // Comment 5 return $id; } }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/partially_generated_empty_section.php
<?hh // strict // @partially-generated class Foo { function a () : int { return 0; } /* BEGIN MANUAL SECTION */ /* END MANUAL SECTION */ function b () : int { return 0; } /* BEGIN MANUAL SECTION */ function c () : int { /* HH_FIXME[4110] */ return vec[ 1 , 2 , 3 ]; } /* END MANUAL SECTION */ }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/partially_generated_only_empty_sections.php
<?hh // strict // @partially-generated class Foo { function a () : int { return 0; } /* BEGIN MANUAL SECTION */ /* END MANUAL SECTION */ function b () : int { return 0; } /* BEGIN MANUAL SECTION */ /* END MANUAL SECTION */ function c () : int { return 0; } }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/range_function_call.php
<?hh f( self::getBuilder() ->setSomeProperty(self::$thing) ->setSomeOtherProperty(self::$ids['stuff']) ->genSave(), self::getBuilder() ->setAnotherProperty(self::$item) ->setYetAnotherProperty(self::$value) ->setOneMoreProperty(vec[self::$junk]) ->genSave(), );
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/xhp_partial_1.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. final class :MyFancyXHPClass extends :OtherXHPThing { protected async function genXHP(): Awaitable<:xhp> { $button = <x:button use="primary">Click This Extra Extra Extra Long Text</x:button>; $link = <x:link href="#">Click This</x:link>; $clickable_sq = <div style="width: 100px; height: 100px; background: blue;" />; $ret = <x:column-layout-component attr1="attr" attr2={ FakeClassWithReallyLongAttributeStuff::getCreateSomeStaticData(Map { 'key1' => 'value1', }) }> <x:div padding="large"> <x:link href="#">Click Here!</x:link> </x:div> <x:div padding="large"> {$link} </x:div> <x:div padding="large"> <!-- Here is a multiline comment that is very unhelpful. In fact, it is strange that it exists at all, let alone takes up multiple lines --> <x:form id="form" method="post" > <x:text-input name="input" placeholder="Type a message." /> <x:button use="primary">Submit Form</x:button> <x:button use="other">This is a decoy button meant to confuse you</x:button> </x:form> </x:div> </x:column-layout-component>; PostXHPVariableSetLinesToCheckForPartialForamtting::go(Vector { 1, 2, 3, 4}, Vector {5, 6, 7 , 8}); return $ret; } }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/xhp_partial_2.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. final class :MyFancyXHPClass extends :OtherXHPThing { protected async function genXHP(): Awaitable<:xhp> { $button = <x:button use="primary">Click This Extra Extra Extra Long Text</x:button>; $link = <x:link href="#">Click This</x:link>; $clickable_sq = <div style="width: 100px; height: 100px; background: blue;" />; $ret = <x:column-layout-component attr1="attr" attr2={ FakeClassWithReallyLongAttributeStuff::getCreateSomeStaticData(Map { 'key1' => 'value1', }) }> <x:div padding="large"> <x:link href="#">Click Here!</x:link> </x:div> <x:div padding="large"> {$link} </x:div> <x:div padding="large"> <!-- Here is a multiline comment that is very unhelpful. In fact, it is strange that it exists at all, let alone takes up multiple lines --> <x:form id="form" method="post" > <x:text-input name="input" placeholder="Type a message." /> <x:button use="primary">Submit Form</x:button> <x:button use="other">This is a decoy button meant to confuse you</x:button> </x:form> </x:div> </x:column-layout-component>; PostXHPVariableSetLinesToCheckForPartialForamtting::go(Vector { 1, 2, 3, 4}, Vector {5, 6, 7 , 8}); return $ret; } }
PHP
hhvm/hphp/hack/test/hackfmt/range_tests/xhp_partial_3.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. final class :MyFancyXHPClass extends :OtherXHPThing { protected async function genXHP(): Awaitable<:xhp> { $button = <x:button use="primary">Click This Extra Extra Extra Long Text</x:button>; $link = <x:link href="#">Click This</x:link>; $clickable_sq = <div style="width: 100px; height: 100px; background: blue;" />; $ret = <x:column-layout-component attr1="attr" attr2={ FakeClassWithReallyLongAttributeStuff::getCreateSomeStaticData(Map { 'key1' => 'value1', }) }> <x:div padding="large"> <x:link href="#">Click Here!</x:link> </x:div> <x:div padding="large"> {$link} </x:div> <x:div padding="large"> <!-- Here is a multiline comment that is very unhelpful. In fact, it is strange that it exists at all, let alone takes up multiple lines --> <x:form id="form" method="post" > <x:text-input name="input" placeholder="Type a message." /> <x:button use="primary">Submit Form</x:button> {SomeBracedExpression::withArbitraryContents()} </x:form> </x:div> </x:column-layout-component>; PostXHPVariableSetLinesToCheckForPartialForamtting::go(Vector { 1, 2, 3, 4}, Vector {5, 6, 7 , 8}); return $ret; } }
PHP
hhvm/hphp/hack/test/hackfmt/tests/allow_long_inputs_for_darray.php
<?hh function test(): void { darray[ "key1" => 1, "key2" => 2, "key3" => 3, "key4" => 4, "key5" => 5, "key6" => 6, "key7" => 7, "key8" => 8, "key9" => 9, "key10" => 10, "key11" => 11, "key12" => 12, ]; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/allow_long_inputs_for_varray.php
<?hh function test(): void { varray[ "value1", "value2", "value3", "value4", "value5", "value6","value7", "value8", "value9", "value10", "value11", "value12", ]; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/allow_returning_darray_of_subtype.php
<?hh function provideDarrayOfStringToInt(): darray<string, int> { return darray["tingley" => 0, "meijer" => 1, "dreeves" => 2]; } function provideDarrayOfMixedToArraykey(): darray<mixed, arraykey> { return provideDarrayOfStringToInt(); }
PHP
hhvm/hphp/hack/test/hackfmt/tests/allow_returning_varray_of_subtype.php
<?hh function provideVarrayOfInt(): varray<int> { return varray[0, 1, 2, 3]; } function provideVarrayOfArraykey(): varray<arraykey> { return provideVarrayOfInt(); }
PHP
hhvm/hphp/hack/test/hackfmt/tests/allow_single_line_ifs.php
<?hh // strict // Should be on a single line if (true) print("hi"); // Should not be on a single line if (true) print("hi"); if (true) print("hi"); if (true) { print("this is a"); print("multi line if"); } if (true) print("this is not a"); print("multi line if"); // Should all have the if body on a new line if (true) this_is_a_very_long_function_call_that_really_exceeds_the_line_length_lorem_ipsum_dolor_sit_amet_consectetur_adipiscing_elit(); if (true) this_is_a_very_long_function_call_that_really_exceeds_the_line_length_lorem_ipsum_dolor_sit_amet_consectetur_adipiscing_elit(); if (true) this_is_a_very_long_function_call_that_really_exceeds_the_line_length_lorem_ipsum_dolor_sit_amet_consectetur_adipiscing_elit(); // Should preserve the single line if f(g($a, $b), () ==> { if (true) print('hi'); if (true) print('hi'); }); if (true) { print('hi'); if (true) print('hi'); } if ($a) f(); else if ($b) g(); else h(); if ($a) f(); else if ($b) g(); else h(); if ($a) f(); else if ($b) { g(); } else h(); if ($a) f(); else if ($b) { g(); } else{ h(); } if ($a) f(); else if ($b) { g(); g2(); } else h(); if ($a) f(); else if ($b) { g(); g2(); } else h(); if ($this->head->isEmpty()) return new MyQueue($this->head->push($item), $this->tail); else return new MyQueue($this->head, $this->tail->push($item)); if ($this->head->isEmpty()) return new MyQueue($this->head->push($item), $this->tail); else return new MyQueue($this->head, $this->tail->push($item));
PHP
hhvm/hphp/hack/test/hackfmt/tests/allow_two_type_parameters_for_darray.php
<?hh function test(): darray<string, int> { return darray["tingley" => 0, "meijer" => 1, "dreeves" => 2]; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/anonymous_function_args.php
<?hh function_call( function() {}, (function() {})(), function() { $short_function = 'is short'; }, function() { $longer_function = 'cannot as easily be fit into one line'; $on_account_of = 'its multiple long statements'; }, $foo, );
PHP
hhvm/hphp/hack/test/hackfmt/tests/attribute_on_parameter.php
<?hh interface I { public function getFoo<<<__Enforceable>>reify Tfoo>(): ?Tfoo; public function getBar<<<__Enforceable>>reify Tbar as IBaaaaaaaaaaaaaaaaaaar>(): ?Tbar; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/attribute_specifications.php
<?hh // strict class FooIsNotBrokenTest extends FooTest { << Override >> public function foo(): int { return 5; } << DataProvider('provideFooEnvironment'), ExpectedException('FooIsBrokenException'), ExpectedExceptionCode( 'ErrorCode::FOO_IS_BROKEN_AND_CANNOT_POSSIBLY_BE_FIXED', ) >> public function testFoo(FooEnvironment $env) { if ($env->isFooBroken()) { throw new FooIsBrokenException(); } } } <<Attr1,Attr2 >>class C { <<Attr1,Attr2 >>public function f<<<__Soft>>reify T>(<<__Soft>>int $x):<<__Soft>>void {} } function f(<<ReallyOverlyLongAttributeNameForTest>> int $reallyOverlyLongVariableNameForTest): void { <<Attr>> ($x) ==> $x * $x; <<AnotherReallyOverlyLongAttributeNameForTest>> ($sameXParameterButMuchLongerForTest) ==> multiplyButLonger( $sameXParameterButMuchLongerForTest, $sameXParameterButMuchLongerForTest); <<Attr>> function (<<__Soft>>int $x):<<__Soft>>void { return $x * $x; }; <<AnotherReallyOverlyLongAttributeNameForTest>> function ( <<__Soft>> string $x, <<__Soft, YetAnotherEvenMoreOverlyLongAttributeNameForTest>>int $sameXParameterButMuchLongerForTest, ):<<__Soft>>void { return multiplyButLonger($sameXParameterButMuchLongerForTest, $sameXParameterButMuchLongerForTest); }; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/awaitable_creation_expressions.php
<?hh async function gen_awaitable_creation_expression_test(): Awaitable<void> { await async { $bar = await async { return get_bar(); }; $foo = await gen_value_of_foo_from_bar($bar); return $foo; } |> gen_set_value_of_with_awaitable_foo($$); async { return await gen_simple(); }; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/binary_expression_argument_nesting.php
<?hh // strict fn( $foo______________________________ === 1 && $bar______________________________ === 2, $baz______________________________ === 3 && $qux______________________________ === 4, );
PHP
hhvm/hphp/hack/test/hackfmt/tests/binary_expression_nesting_1.php
<?hh $a = $long_long_long_long_long_long_long_long_long_long_name_1 + $long_long_long_long_long_long_long_long_long_long_name_2; $long_long_long_long_long_long_long_long_long_long_name_ret = $long_long_long_long_long_long_long_long_long_long_name_1 + $long_long_long_long_long_long_long_long_long_long_name_2; if ( $long_long_long_long_long_long_long_long_long_long_name_1 === $long_long_long_long_long_long_long_long_long_long_name_1 || $long_long_long_long_long_long_long_long_long_long_name_2 ) { } if ( $aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * $bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + $cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc * $dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd + $eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ) { } if ( $aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + $bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + $cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc === $dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd ) { } if ( $aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa === $bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb || $cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc === $dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd ) { } if ( $aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * $bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + $cccccccccccccccccccccccccccccc * $dddddddddddddddddddddddddddddd + $eeeeeeeeeeeeeeeeeeeeeeeeeeeeee ) { } if ( $aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + $bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + $cccccccccccccccccccccccccccccc === $dddddddddddddddddddddddddddddd ) { } if ( $aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa === $bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb || $cccccccccccccccccccccccccccccc === $dddddddddddddddddddddddddddddd ) { }
PHP
hhvm/hphp/hack/test/hackfmt/tests/braced_item_whitespace.php
<?hh $foo[$a_____________________][$b____________________________][$c____________________]; $foo[$a_____________________][$b____________________________]['c____________________']; $foo[$a_____________________][$b____________________________][100000000000000000000]; $foo[$a_____________________][$b____________________________][ $c____________________ ]; $foo[$a_____________________][$b____________________________][ 'c____________________' ]; $foo[$a_____________________][$b____________________________][ 100000000000000000000 ];
PHP
hhvm/hphp/hack/test/hackfmt/tests/builder_pattern_preserves_linebreaks.php
<?hh $config ->methodA() ->methodB() ->methodC() ->methodD(); $config ->propertyA ->methodB() ->methodC() ->methodD(); $config->methodA()->methodB()->methodC()->methodD();
PHP
hhvm/hphp/hack/test/hackfmt/tests/builtin_parentheses.php
<?hh print 'foo'; print('foo'); print ('foo'); echo 'foo'; echo('foo'); echo ('foo'); include 'foo'; include('foo'); include ('foo'); include_once 'foo'; include_once('foo'); include_once ('foo'); require 'foo'; require('foo'); require ('foo'); require_once 'foo'; require_once('foo'); require_once ('foo');
PHP
hhvm/hphp/hack/test/hackfmt/tests/case_types.php
<?hh case type CT1 = int | string | bool; case type CT2 = | int | string | bool; case type MultiLineCT1 = int | string | bool | nonnull | null | mixed | (function(int, string, bool): void); case type MultiLineCT2 = | int | string | bool | nonnull | null | mixed | (function(int, string, bool): void);
PHP
hhvm/hphp/hack/test/hackfmt/tests/casts_in_last_arg_position.php
<?hh function f(dynamic $x_________, dynamic $y__________________________): void { $x_________->foo('%s input is not valid', $y__________________________ as string); $x_________->foo('%s input is not valid', $y__________________________ ?as string); $x_________->log('%s input is a string', $y__________________________ is string); }
PHP
hhvm/hphp/hack/test/hackfmt/tests/chaining_preserves_initial_linebreak.php
<?hh $result = await $groups->query() ->genFirstResult(); $result = await $groups ->query() ->genFirstResult();
PHP
hhvm/hphp/hack/test/hackfmt/tests/ClassishHeaders.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. abstract class ClassishHeaders extends ClassishHeadersBase implements IClassishHeaders, IHeaders, IClassish, IAbstract { } abstract class ClassishHeadersWithAnExtremelyLongNameThatMakesNoSense extends ClassishHeadersBase implements IClassishHeaders, IHeaders, IClassish, IAbstract { } abstract class ClassishHeadersWithAnExtremelyLongNameThatMakesNoSenseBase extends ClassishHeadersBase implements IClassishHeaders, IHeaders, IClassish, IAbstract, IPutsTheExtendsListOverLineLength { } interface IClassishHeaders extends IHeaders, IClassish, IInterface, IPutsThisOverLineLengths { } interface IClassishHeaders extends IHeaders, IClassish, IInterface, IPutsThisOverLineLength, IPutsTheExtendsListOverLineLength { }
PHP
hhvm/hphp/hack/test/hackfmt/tests/class_keyword_split.php
<?hh abstract class E_____________________<T_____________ as I_________________, T as I_______> { }
PHP
hhvm/hphp/hack/test/hackfmt/tests/coeffects.php
<?hh function f( (function ()[_]: void) $f, vec<int> $v )[ctx $f, $v::C, rx]: void { } function g( (function ()[_]: void) $f______________________________, vec<int> $v______________________________ )[ctx $f______________________________, $v______________________________::C, rx]: void { }
PHP
hhvm/hphp/hack/test/hackfmt/tests/collection_literal_trailing_comma.php
<?hh $vec = Vector {$foo}; $vec = Vector {$foo,}; $vec = Vector {$foo, $bar}; $vec = Vector {$foo, $bar,}; $vec = Vector {$foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo}; $vec = Vector {$foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo,}; $vec = Vector {$fooooooooooooooooooooooooooooo, $baaaaaaaaaaaaaaaaaaaaaaaaaaaar}; $vec = Vector {$fooooooooooooooooooooooooooooo, $baaaaaaaaaaaaaaaaaaaaaaaaaaaar,}; $vec = Vector {$foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo}; $vec = Vector {$foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo,}; $vec = Vector {$fooooooooooooooooooooooooooooooooooo, $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar}; $vec = Vector {$fooooooooooooooooooooooooooooooooooo, $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar,}; $vec = Vector {$foo /* foo */}; $vec = Vector {$foo, /* foo */}; $vec = Vector { $foo // foo }; $vec = Vector { $foo, // foo }; $vec = Vector { $foo // foo , }; $vec = Vector {/* leading comment */ $fooooooooooooooooo /* trailing comment */}; $vec = Vector {/* leading comment */ $fooooooooooooooooo, /* trailing comment */}; $vec = Vector { /* leading comment */ $foooooooooooooooo /* trailing comment */ }; $vec = Vector { /* leading comment */ $foooooooooooooooo, /* trailing comment */ }; $vec = Vector { /* leading comment */ $foooooooooooooooo /* trailing comment */ , };
PHP
hhvm/hphp/hack/test/hackfmt/tests/comment_indentation.php
<?hh// strict bake_bread( // rye ); preheat_oven( $temp, $time, // celsius ); find_caraway_seed(/* somewhere */); grease_tin( /* nonstick spray */ ); get_electric_mixer(/* plug in */ ); mixer_settings($minutes, $speed /* nullable */); mixer_settings(/* mins */ $minutes /* nullable */, /* spd */ $speed); mixer_settings(/*mins*/$minutes/*null*/,/*spd*/$speed/*null*/); mixer_settings( /*mins*/ $minutes /*null*/ , /*spd*/ $speed /*null*/ ); mix_dough( $flour, $butter, /* $molasses */ ); beat_mixture( /* looooooooooooooooooooooooooooooooooooooooooooooooooooooong time */ ); knead_dough( $smoothness_to_be_obtained, $time_to_be_spent_kneading, /* usually about 5 mins */ ); punch_dough($violence, $duration /** * This duration is important. */); brush_with( $cooking_oil, $generousness, /** * Don't be too generous. */ ); slash_top( $knife, $times, /** * Only a few times needed. */ ); emptee($oven /* yep */); emptee( $tin /* nope */ ); emptee( /* let */ $bread /* rise */ ); function isKitchenEmpty(): bool { return // check oven first $this->oven_contents === '' && $this->tin_contents === null && $this->mixer_contents === null && $this->items_on_counter === 0; // now we've checked everything }
PHP
hhvm/hphp/hack/test/hackfmt/tests/concat_operator.php
<?hh $foo = 'bar' . $baz; $str = 'short string'.$very_long_variable_name_which_probably_ought_to_be_shortened; $str = 'not as short string'.$very_long_variable_name_which_probably_ought_to_be_shortened; $str = $first . $second . $third . $fourth . $fifth . $sixth . $seventh . $eighth . $ninth . $tenth . $eleventh . $twelfth; $str = $one . $two + $three; function_call( '/' . $regex . '/S', $long_argument_triggering_line_breaks_for_argument_list, );
PHP
hhvm/hphp/hack/test/hackfmt/tests/concat_with_numbers.php
<?hh $str = "foo" . 100 . "bar"; $str = "foo" . 0755 . "bar"; $str = "foo" . 0xdeadbeef . "bar"; $str = "foo" . 0b01100010 . "bar"; $str = "foo" . 100.0 . "bar"; $style = "background-size:" . 100 * $pages . "% auto;" . "padding-bottom:" . $height / $width * 100 . "%;" . "background-image: url(" . $background . ")";
PHP
hhvm/hphp/hack/test/hackfmt/tests/const_declarators.php
<?hh class Tiger { const vec<string> TIGER; const vec<string> SYMMETRY = vec[ 'Tiger, tiger, burning bright', 'In the forests of the night', 'What immortal hand or eye', 'Could frame thy fearful symmetry?', ]; const vec<string> FIRE = vec[ 'In what distant deeps or skies', 'Burnt the fire of thine eyes?', 'On what wings dare he aspire?', 'What the hand dare seize the fire?', ], HEART = vec[ 'And what shoulder and what art', 'Could twist the sinews of thy heart?', 'And when thy heart began to beat,', 'What dread hand and what dread feet?', ]; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/container_literal_newlines.php
<?hh // strict $foo = varray['should_stay_on_same_line']; $foo = varray[ 'should_remain_on_new_line', ]; $foo = varray['should_stay_on_same_line']; $foo = varray[ 'should_remain_on_new_line', ]; $foo = darray['should_stay' => 'on_same_line']; $foo = darray[ 'should_remain' => 'on_new_line', ]; $foo = darray['should_stay' => 'on_same_line']; $foo = darray[ 'should_remain' => 'on_new_line', ]; $foo = Set { 'should_stay_on_same_line' }; $foo = Set { 'should_remain_on_new_line', }; $foo = Vector { 'should_stay_on_same_line' }; $foo = Vector { 'should_remain_on_new_line', }; $foo = Map { 'should_stay' => 'on_same_line' }; $foo = Map { 'should_remain' => 'on_new_line', }; $foo = keyset['should_stay_on_same_line']; $foo = keyset[ 'should_remain_on_new_line', ]; $foo = vec['should_stay_on_same_line']; $foo = vec[ 'should_remain_on_new_line', ]; $foo = dict['should_stay' => 'on_same_line']; $foo = dict[ 'should_remain' => 'on_new_line', ]; // If there are no elements, there should not be a newline. $foo = dict[ ]; type Foo = shape('should_stay' => OnSameLine); type Foo = shape( 'should_remain' => OnNewLine, ); type Foo = shape('should_stay' => OnSameLine, ...); type Foo = shape( 'should_remain' => OnNewLine, ... ); foo(shape('should_stay' => 'on_same_line')); foo(shape( 'should_remain' => 'on_new_line', ));
PHP
hhvm/hphp/hack/test/hackfmt/tests/context_const_constraint_list.php
<?hh abstract class A { abstract const ctx C super [output]; } abstract class B { abstract const ctx C super [output] as [output]; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/delimited_comments.php
<?hh // strict /** * The status associated with foo. */ function getFooStatus() { /* BEGIN FOO SECTION */ return FooStatus(); /* END FOO SECTION */ }
PHP
hhvm/hphp/hack/test/hackfmt/tests/delimited_comment_indentation.php
<?hh abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /* ErrorCode::DISABLED => 'disabled', */ /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /* ErrorCode::DISABLED => 'disabled', */ /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /* ErrorCode::DISABLED => 'disabled', *//** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /* ErrorCode::DISABLED => 'disabled', */ /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /* ErrorCode::DISABLED => 'disabled', */ /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /* ErrorCode::DISABLED => 'disabled', */ /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /* ErrorCode::DISABLED => 'disabled', */ /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /* ErrorCode::DISABLED => 'disabled', */ /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; } abstract final class ErrorDescriptions { private static array $descriptions = darray[ ErrorCode::FATAL => 'Fatal', /* ErrorCode::DISABLED => 'disabled', */ /** * Foo Errors */ ErrorCode::FOO_PARSE_FAILED => 'Foo could not be parsed', ErrorCode::FOO_DISPATCH_FAILED => 'Failed to dispatch Foo', ]; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/doc_string_literals_v2.php
<?hh $str = <<<EOT foo EOT; function_call(<<<EOTA foo EOTA ); function_call(<<<EOTB foo EOTB , <<<EOTC bar EOTC ); $str = <<<'EOTD' foo EOTD; function_call(<<<'EOTE' foo EOTE ); function_call(<<<'EOTF' foo EOTF , <<<'EOTG' bar EOTG ); function_call( $arg, <<<EOTH foo EOTH ); function_call($arg, <<<EOTI foo EOTI ); function_call( $arg1, <<<EOTJ foo EOTJ , $arg2, ); function foo() { $bar = "bar"; // SyntaxList of HeredocStringLiteralHead, etc return JSON::decode(<<<JSON { "foo": "{$bar}" } JSON ); } function bar() { // HeredocStringLiteral return JSON::decode(<<<JSON { "foo": "bar" } JSON ); } function baz() { // NowdocStringLiteral return JSON::decode(<<<'JSON' { "foo": "{$bar}" } JSON ); } $csv = <<<CSV 2017-04-07,$some_variable,frankenstein,dracula,chocula,wolverine,http://www.longlines.com; 2017-04-07,2,frankenstein,dracula,chocula,wolverine,http://www.longlines.com; 2017-04-07,{$some_variable},frankenstein,dracula,chocula,wolverine,http://www.longlines.com; 2017-04-07,2,frankenstein,dracula,chocula,wolverine,http://www.longlines.com; 2017-04-07,$object->member,frankenstein,dracula,chocula,wolverine,http://www.longlines.com; 2017-04-07,{$some_variable[$index1 + $index2]},frankenstein,dracula,chocula,wolverine,http://www.longlines.com; CSV;
PHP
hhvm/hphp/hack/test/hackfmt/tests/doc_string_literals_v3.php
<?hh $str = <<<EOT foo EOT; function_call(<<<EOTA foo EOTA ); function_call(<<<EOTB foo EOTB , <<<EOTC bar EOTC ); $str = <<<'EOTD' foo EOTD; function_call(<<<'EOTE' foo EOTE ); function_call(<<<'EOTF' foo EOTF , <<<'EOTG' bar EOTG ); function_call( $arg, <<<EOTH foo EOTH ); function_call($arg, <<<EOTI foo EOTI ); function_call( $arg1, <<<EOTJ foo EOTJ , $arg2, ); function foo() { $bar = "bar"; // SyntaxList of HeredocStringLiteralHead, etc return JSON::decode(<<<JSON { "foo": "{$bar}" } JSON ); } function bar() { // HeredocStringLiteral return JSON::decode(<<<JSON { "foo": "bar" } JSON ); } function baz() { // NowdocStringLiteral return JSON::decode(<<<'JSON' { "foo": "{$bar}" } JSON ); } $csv = <<<CSV 2017-04-07,$some_variable,frankenstein,dracula,chocula,wolverine,http://www.longlines.com; 2017-04-07,2,frankenstein,dracula,chocula,wolverine,http://www.longlines.com; 2017-04-07,{$some_variable},frankenstein,dracula,chocula,wolverine,http://www.longlines.com; 2017-04-07,2,frankenstein,dracula,chocula,wolverine,http://www.longlines.com; 2017-04-07,$object->member,frankenstein,dracula,chocula,wolverine,http://www.longlines.com; 2017-04-07,{$some_variable[$index1 + $index2]},frankenstein,dracula,chocula,wolverine,http://www.longlines.com; CSV;
hhvm/hphp/hack/test/hackfmt/tests/dune
(rule (alias verify) (deps %{exe:../../../src/hackfmt.exe} %{project_root}/hack/test/verify.py %{project_root}/hack/test/review.sh (glob_files %{project_root}/hack/test/hackfmt/tests/*.flags) (glob_files %{project_root}/hack/test/hackfmt/tests/*.php) (glob_files %{project_root}/hack/test/hackfmt/tests/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/hackfmt/tests --program %{exe:../../../src/hackfmt.exe} --idempotence --flags --test))) (alias (name runtest) (deps (alias verify)))
PHP
hhvm/hphp/hack/test/hackfmt/tests/effect_encapsulation.php
<?hh <<file:__EnableUnstableFeatures('context_alias_declaration_short')>> newctx C as [write_props];
PHP
hhvm/hphp/hack/test/hackfmt/tests/empty_braces.php
<?hh class A {} class B { } class C { } class D { /* TODO */ } class E { /* TODO */ } function foo() {} function bar() { } function baz() { } function qux() { /* TODO */ } function qud() { /* TODO */ } if (true) {} if (true) { } if (true) { } if (true) { /* TODO */ } if (true) { /* TODO */ } class Test { public function foo() {} public function bar() { } public function baz() { } public function qux() { /* TODO */ } public function qud() { /* TODO */ } }
PHP
hhvm/hphp/hack/test/hackfmt/tests/enum_class.php
<?hh enum class Foo : mixed { string A = 'a'; } enum class Foo: IFoo extends Bar { FooBarFrameworkParam<bool, bool> baz = FooBarFrameworkParam::bool()->withDefaultOf(false); }
PHP
hhvm/hphp/hack/test/hackfmt/tests/enum_declaration.php
<?hh enum Foo: string { VARIANT_A_______________________________ = SomeClass::class; VARIANT_B_______________________________ = SomeOtherClass_______________::class; VARIANT_C_______________________________ = 'xxxxxxxxxxxxxxxxxxxxxx'.'yyyyyyyyyyyyyyyyyy'; VARIANT_D_______________________________ = 'xxxxxxxxxxxxxxxxxxxxxx'.'yyyyyyyyyyyyyyyyyy'.'zzzzzzzzzzzzzzzzzzzzzzzzzzzzz'; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/enum_supertyping.php
<?hh enum E: string { use A; use B; use C, D; use E_______________________________________, F________________________________; FOO = 'foo'; BAR = 'bar'; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/expr_tree.php
<?hh function foo(): void { $basic = Bar`baz()`; $splice = Bar`1 + ${baz()}`; $block_empty = Bar`{ }`; $block_basic = Bar`{call();}`; $multi_line_block = Bar` { $x = 10; return $x + $x; } `; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/fixme_suppresses_formatting_at_end_of_file.php
<?hh type UNSAFE_TYPE_HH_FIXME_< T> = T; function with_unsafe_type_hh_fixme(UNSAFE_TYPE_HH_FIXME $x): int { return $x; } // NB: NO TRAILING NEWLINE AT END OF FILE /* HH_FIXME[4101] */ type UNSAFE_TYPE_HH_FIXME = \UNSAFE_TYPE_HH_FIXME_;
PHP
hhvm/hphp/hack/test/hackfmt/tests/foreach_overflow.php
<?hh foreach ($foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo as $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar) { // ... } foreach ($foooooooooooooooooooooooooooooooooooooooo as $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar => $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz) { // ... } foreach ($foooooooooooooooooooooooo as $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar => $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz) { // ... } foreach ($foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo as $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar => $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz) { // ... } foreach ($foo as list($baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar, $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz)) { // ... } foreach ($foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo as list($baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar, $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz)) { // ... } foreach ($foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo as list($baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar, $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz)) { // ... } foreach ($foo as $bar => list($baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz1, $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz2)) { // ... } foreach ($foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo as $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar => list($baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz1, $baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz2)) { // ... }
PHP
hhvm/hphp/hack/test/hackfmt/tests/foreach_simple.php
<?hh foreach ($foo as $bar) { consume($bar); } foreach ($foo as $bar => $baz) { consume($bar, $baz); }
PHP
hhvm/hphp/hack/test/hackfmt/tests/for_with_multiple_exprs.php
<?hh for($i=0,$j=0,$k=0; $i+$j+$k<10; $i++,$j++,$k++) { echo $i; } for ( $iiiiiiiiiiiiiiiiiiii = 0, $jjjjjjjjjjjjjjjjjjjj = 0, $kkkkkkkkkkkkkkkkkkkk = 0; $iiiiiiiiiiiiiiiiiiii < $length; $iiiiiiiiiiiiiiiiiiii++, $jjjjjjjjjjjjjjjjjjjj++, $kkkkkkkkkkkkkkkkkkkk++ ) { }
PHP
hhvm/hphp/hack/test/hackfmt/tests/function_call_with_type_arguments.php
<?hh // strict function test(dynamic $foo): void { $foo->getSomeValue<ExplicitTypeArgument1>(); $foo->getSomeValue<ExplicitTypeArgument1, ExplicitTypeArgument2>(); $foo->getSomeValue<ExplicitTypeArgument1, ExplicitTypeArgument2, ExplicitTypeArgument3>(); $foo->getSomeValue<ExplicitTypeArgument1, ExplicitTypeArgument2, ExplicitTypeArgument3>(1, 2, 3); $foo->getSomeValue<ExplicitTypeArgument1, ExplicitTypeArgument2, ExplicitTypeArgument3>(111111111111111111111111, 222222222222222222222222, 333333333333333333333333); $foo->getSomeValue<ExplicitTypeArgument1>() ->getSomeValue<ExplicitTypeArgument1, ExplicitTypeArgument2>() ->getSomeValue<ExplicitTypeArgument1, ExplicitTypeArgument2, ExplicitTypeArgument3>(1, 2, 3) ->getSomeValue<ExplicitTypeArgument1, ExplicitTypeArgument2, ExplicitTypeArgument3>(111111111111111111111111, 222222222222222222222222, 333333333333333333333333); }
PHP
hhvm/hphp/hack/test/hackfmt/tests/function_hints.php
<?hh class Foooooooooooo {} class Baaaaaaaaaaar {} function f((function (Foooooooooooo, Baaaaaaaaaaar, Foooooooooooo, Baaaaaaaaaaar): Foooooooooooo) $x): void {} function g((function ( ... ) :Foooooooooooo) $x): void{} function h((function (Foooooooooooo ...) :Foooooooooooo) $x): void{} function i((function (Baaaaaaaaaaar, Baaaaaaaaaaar, Foooooooooooo... ) :Foooooooooooo) $x): void{} function j((function (Baaaaaaaaaaar, Baaaaaaaaaaar, ...) :Foooooooooooo) $x): void{}
PHP
hhvm/hphp/hack/test/hackfmt/tests/hh_fixmes_suppress_breaking_function_header.php
<?hh class C { // If we don't suppress formatting, we'll reflow this function header to fit // in the line length limit. private function getFooBarLink(<<__Soft>> int $a, $b, bool $is_fantastic): ?:bootstrap:link { $a; $b; $c; $d; $e; $f; $g; } // If an HH_FIXME is applied (to suppress an error on one of the parameters), // we don't want to reflow--it would move the parameter away from the FIXME, // so that the error would no longer be silenced. We need to suppress // formatting on the function header, but... /* HH_FIXME[4032] */ private function getBetterFooBarLink( <<__Soft>> int $a, $b, bool $is_fantastic ): ?:bootstrap:link { // ...the contents of the function should still be formatted. $a; $b; $c; $d; $e; $f; $g; } }
PHP
hhvm/hphp/hack/test/hackfmt/tests/hh_fixmes_suppress_breaking_next_line.php
<?hh /* HH_FIXME[4110] */ class HasFixme { public function why() { // Here is a motivating example for the fixmes-suppress-formatting feature. // We do not want to format this node because it would move the suppression // comment away from the error, causing it to fail to suppress the error: /* HH_FIXME[4110] */ f($some_type_error_we_would_like_to_suppress, $xxxxxxxxxx, $yyyyyyyyyy, $zzzzzzzzzz); } public function cases() { // The FIXME on the class definition only suppresses formatting for the // first line (containing the tokens "class" "HasFixme" "{"). Statements // inside the class, like this one, are still formatted normally. $this_is + $formatted; /* HH_FIXME[1111] */ func($not_formatted, $formatted, $formatted); /* HH_FIXME[2222] */ func($not_formatted, $formatted); /* HH_FIXME[3333] */ func($not_formatted, $not_formatted, $formatted, $formatted); /* HH_FIXME[1000] */// not formatted /* HH_FIXME[2000] */ // not formatted /* HH_FIXME[3000] */ func($not_formatted, $not_formatted, $formatted, $formatted); /* HH_FIXME[4444] */ f($some_type_error_we_would_like_to_suppress, $xxxxxxxxxx, $yyyyyyyyyy, $zzzzzzzzzz) + $this_part_of_the_expression + $is_still_formatted; /* HH_FIXME[4297] */ expect(PHPism_FIXME::varrayFuzzyEqualsDarray($config['foo'], varray[ 'apples', 'oranges', 'kiwis', 'pears', ]))->toBeTrue(); } }
PHP
hhvm/hphp/hack/test/hackfmt/tests/if_elseif_else.php
<?hh if ($var == 0) { overly_long_func($longlongparam1 + $longparam2, another_nested_function_call()); } else if ($boo) { foo(); } else { baz(); }
PHP
hhvm/hphp/hack/test/hackfmt/tests/if_else_if_else.php
<?hh if ($x > 3) { // ... } else if ($x === null || $x === 'null') { // ... } else if ( ($my_int_to_be_tested === 1 || $my_int_to_be_tested === 2) && $we_care_about_that_int ) { // ... } else if (multiline_function( $unrealistically_lengthened_argument, $another_unusually_long_winded_argument, )) { // ... } else { // ... }
PHP
hhvm/hphp/hack/test/hackfmt/tests/ignore_format_1.php
<?hh function test(): void { $a = vec[ 1, 2, 3, 4, 5 ]; // hackfmt-ignore - this should work $b = vec[ 2, 3, 4, 5, 6 ]; $c = vec[ 1, 2, 3, 4, 5 ]; // hackfmt-ignore - this should work $d = vec[ 2, 3, 4, 5, 6 ]; // some comment that should not disappear $e = vec[ 1, 2, 3, 4, 5 ]; // hackfmt-ignore - this should work $f = vec[ 2, 3, 4, 5, 6 ]; $g = vec[ 1, 2, 3, 4, 5 ]; $h = vec[ // hackfmt-ignore - this should not work 3, 4, 5, 6, 7 ]; $i = vec[ 4, 5, 6, 7, 8 ]; /* hackfmt-ignore - this multiline comment should also work */ $j = vec[ 4, 5, 6, 7, 8 ]; $k = vec[ 5, 6, 7, 8, 9 ]; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/ignore_format_2.php
<?hh function test(): vec<int> { $x = functionCall() + // hackfmt-ignore - this should be left as-is otherFunctionCall(vec[ 111111111111, 222222222222, 333333333333, 444444444444, 555555555555, 666666666666, 777777777777, 888888888888, 999999999999, ]); $y = functionCall() + // this should be formatted otherFunctionCall(vec[ 444444444444, 555555555555, 666666666666, 777777777777, 888888888888, 999999999999, 111111111111, 222222222222, 333333333333, ]); // hackfmt-ignore - this should be left as-is $z = otherFunctionCall(vec[111111111111, 222222222222, 333333333333, 444444444444, 555555555555, 666666666666, 777777777777, 888888888888, 999999999999,]); // This should be formatted $zzz = otherFunctionCall(vec[111111111111, 222222222222, 333333333333, 444444444444, 555555555555, 666666666666, 777777777777, 888888888888, 999999999999,]); f(() ==> { // hackfmt-ignore - this should be left as-is vec[ $zzz, 200, 300, 400, $zzz, 600, 700, 800, $zzz, ]; }); // hackfmt-ignore - this should be left as-is return vec[ $x, $y, $z, $z, $x, $y, $y, $z, $x, ]; } function functionCall(): int { // hackfmt-ignore - this should be left as is $a = 1 + 2 + 3; // This should be formatted $b = 4 + 5 + 6; // hackfmt-ignore - this should left as-is return $a + $b; } function otherFunctionCall(vec<int> $v): int { $a = 0; // hackfmt-ignore - this should be left as-is foreach ($v as $key => $value) { $a += $value; } // This should be formatted foreach ($v as $key => $value) { $a += $key; } return $a; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/ignore_format_3.php
<?hh function test(): void { // It's possible to format the following in such a way that would make // the ignore comment to appear in the trailing trivia after formatting, // instead of the leading trivia, where it appeared before. This would // create a situation where formatting the document would not be idempotent. $x = /*hackfmt-ignore*/ (3+1) ; }
PHP
hhvm/hphp/hack/test/hackfmt/tests/indent_width_4.php
<?hh // strict class Point { private $x; // Cartesian x-coordinate private $y; // Cartesian y-coordinate public function __construct($x = 0, $y = 0) { $this->x = $x; $this->y = $y; } public function move($x, $y) { $this->x = $x; $this->y = $y; } public function translate($x, $y) { $this->x += $x; $this->y += $y; } public function magnitude() { return sqrt($this->x ** 2 + $this->y ** 2); } public function __toString() { return '(' . $this->x . ',' . $this->y . ')'; } }
PHP
hhvm/hphp/hack/test/hackfmt/tests/indent_with_tabs.php
<?hh // strict class Point { private $x; // Cartesian x-coordinate private $y; // Cartesian y-coordinate public function __construct($x = 0, $y = 0) { $this->x = $x; $this->y = $y; } public function move($x, $y) { $this->x = $x; $this->y = $y; } public function translate($x, $y) { $this->x += $x; $this->y += $y; } public function magnitude() { return sqrt($this->x ** 2 + $this->y ** 2); } public function __toString() { return '(' . $this->x . ',' . $this->y . ')'; } }