Repository: prettier/plugin-php
Pull request #817 (2018-10-19 11:53:48)

fix: nowdoc and heredoc output in `case` node
Also a lot of tests

evilebottnawi: Feel free to feedback

Patch:
diff --git a/src/util.js b/src/util.js
index 670badd..1ce1ad2 100644
--- a/src/util.js
+++ b/src/util.js
@@ -259,6 +259,10 @@ function docShouldHaveTrailingNewline(path) {
     return true;
   }
 
+  if (parent.kind === "case" && parent.test === node) {
+    return true;
+  }
+
   if (
     parent.kind === "assign" &&
     parent.right === node &&


Test patch:
diff --git a/tests/nowdoc/__snapshots__/jsfmt.spec.js.snap b/tests/nowdoc/__snapshots__/jsfmt.spec.js.snap
index 18cd66d..b4e8970 100644
--- a/tests/nowdoc/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/nowdoc/__snapshots__/jsfmt.spec.js.snap
@@ -215,6 +215,299 @@ string
 string
 string
 EOD;
+
+call(
+    <<<'EOD'
+string
+string
+string
+EOD
+);
+
+call(
+    $a,
+    <<<'EOD'
+string
+string
+string
+EOD
+);
+
+call(
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    $b
+);
+
+$var = new class(
+    <<<'EOD'
+string
+string
+string
+EOD
+) {};
+
+$var = new class(
+    $a,
+    <<<'EOD'
+string
+string
+string
+EOD
+) {};
+
+$var = new class(
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    $b
+) {};
+
+echo <<<'EOD'
+string
+string
+string
+EOD;
+
+echo
+$a,
+<<<'EOD'
+string
+string
+string
+EOD;
+
+echo <<<'EOD'
+string
+string
+string
+EOD
+,
+$a;
+
+print  <<<'EOD'
+string
+string
+string
+EOD;
+
+return  <<<'EOD'
+string
+string
+string
+EOD;
+
+eval(
+<<<'EOD'
+string
+string
+string
+EOD
+);
+
+include <<<'EOD'
+string
+string
+string
+EOD;
+
+exit(
+<<<'EOD'
+string
+string
+string
+EOD
+);
+
+const MIN_VALUE = <<<'EOD'
+string
+string
+string
+EOD;
+
+$var = (bool) <<<'EOD'
+string
+string
+string
+EOD;
+
+class Foo {
+    public $var = <<<'EOD'
+string
+string
+string
+EOD;
+    public const FOO = <<<'EOD'
+string
+string
+string
+EOD;
+
+    public function test($var = <<<'EOD'
+string
+string
+string
+EOD
+    ) {
+    }
+    public function test1($var, $var = <<<'EOD'
+string
+string
+string
+EOD
+    ) {
+    }
+    public function test2($var = <<<'EOD'
+string
+string
+string
+EOD
+        ,
+      $var
+    ) {
+    }
+}
+
+declare(ticks=1) {
+    <<<'EOD'
+string
+string
+string
+EOD;
+    $str = <<<'EOD'
+string
+string
+string
+EOD;
+}
+
+function foo() {
+    <<<'EOD'
+string
+string
+string
+EOD;
+    $str = <<<'EOD'
+string
+string
+string
+EOD;
+}
+
+$var = function () {
+    <<<'EOD'
+string
+string
+string
+EOD;
+    $str = <<<'EOD'
+string
+string
+string
+EOD;
+};
+
+$a = [
+    <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+];
+
+$a = [
+    $a,
+    <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    $a
+];
+
+$a = [
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+    ,
+];
+
+$a = [
+    'other-key' => $a,
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    'other-key' => $a
+];
+
+switch ($i) {
+    case <<<'TXT'
+string
+TXT
+    :
+        print <<<'TXT'
+string
+TXT;
+        break;
+
+    case <<<'TXT'
+other
+TXT
+    :
+        break;
+    default:
+        print <<<'TXT'
+string
+TXT;
+}
+
+
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -467,6 +760,303 @@ string
 string
 EOD;
 
+call(
+    <<<'EOD'
+string
+string
+string
+EOD
+);
+
+call(
+    $a,
+    <<<'EOD'
+string
+string
+string
+EOD
+);
+
+call(
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    $b
+);
+
+$var = new class(
+    <<<'EOD'
+string
+string
+string
+EOD
+) {};
+
+$var = new class(
+    $a,
+    <<<'EOD'
+string
+string
+string
+EOD
+) {};
+
+$var = new class(
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    $b
+) {};
+
+echo <<<'EOD'
+string
+string
+string
+EOD;
+
+echo $a,
+    <<<'EOD'
+string
+string
+string
+EOD;
+
+echo <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    $a;
+
+print <<<'EOD'
+string
+string
+string
+EOD;
+
+return <<<'EOD'
+string
+string
+string
+EOD;
+
+eval(
+    <<<'EOD'
+string
+string
+string
+EOD
+);
+
+include <<<'EOD'
+string
+string
+string
+EOD;
+
+exit(
+    <<<'EOD'
+string
+string
+string
+EOD
+);
+
+const MIN_VALUE = <<<'EOD'
+string
+string
+string
+EOD;
+
+$var = (bool) <<<'EOD'
+string
+string
+string
+EOD;
+
+class Foo
+{
+    public $var = <<<'EOD'
+string
+string
+string
+EOD;
+    public const FOO = <<<'EOD'
+string
+string
+string
+EOD;
+
+    public function test(
+        $var = <<<'EOD'
+string
+string
+string
+EOD
+    )
+    {
+    }
+    public function test1(
+        $var,
+        $var = <<<'EOD'
+string
+string
+string
+EOD
+    )
+    {
+    }
+    public function test2(
+        $var = <<<'EOD'
+string
+string
+string
+EOD
+        ,
+        $var
+    )
+    {
+    }
+}
+
+declare(ticks=1) {
+    <<<'EOD'
+string
+string
+string
+EOD;
+    $str = <<<'EOD'
+string
+string
+string
+EOD;
+}
+
+function foo()
+{
+    <<<'EOD'
+string
+string
+string
+EOD;
+    $str = <<<'EOD'
+string
+string
+string
+EOD;
+}
+
+$var = function () {
+    <<<'EOD'
+string
+string
+string
+EOD;
+    $str = <<<'EOD'
+string
+string
+string
+EOD;
+};
+
+$a = [
+    <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    $a,
+    <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    $a
+];
+
+$a = [
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    'other-key' => $a,
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    'other-key' => $a
+];
+
+switch ($i) {
+    case <<<'TXT'
+string
+TXT
+    :
+        print <<<'TXT'
+string
+TXT;
+        break;
+
+    case <<<'TXT'
+other
+TXT
+    :
+        break;
+    default:
+        print <<<'TXT'
+string
+TXT;
+}
+
 `;
 
 exports[`single.php - php-verify: single.php 1`] = `
diff --git a/tests/nowdoc/nowdoc.php b/tests/nowdoc/nowdoc.php
index 35e27a4..a74558f 100644
--- a/tests/nowdoc/nowdoc.php
+++ b/tests/nowdoc/nowdoc.php
@@ -212,3 +212,296 @@ string
 string
 string
 EOD;
+
+call(
+    <<<'EOD'
+string
+string
+string
+EOD
+);
+
+call(
+    $a,
+    <<<'EOD'
+string
+string
+string
+EOD
+);
+
+call(
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    $b
+);
+
+$var = new class(
+    <<<'EOD'
+string
+string
+string
+EOD
+) {};
+
+$var = new class(
+    $a,
+    <<<'EOD'
+string
+string
+string
+EOD
+) {};
+
+$var = new class(
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    $b
+) {};
+
+echo <<<'EOD'
+string
+string
+string
+EOD;
+
+echo
+$a,
+<<<'EOD'
+string
+string
+string
+EOD;
+
+echo <<<'EOD'
+string
+string
+string
+EOD
+,
+$a;
+
+print  <<<'EOD'
+string
+string
+string
+EOD;
+
+return  <<<'EOD'
+string
+string
+string
+EOD;
+
+eval(
+<<<'EOD'
+string
+string
+string
+EOD
+);
+
+include <<<'EOD'
+string
+string
+string
+EOD;
+
+exit(
+<<<'EOD'
+string
+string
+string
+EOD
+);
+
+const MIN_VALUE = <<<'EOD'
+string
+string
+string
+EOD;
+
+$var = (bool) <<<'EOD'
+string
+string
+string
+EOD;
+
+class Foo {
+    public $var = <<<'EOD'
+string
+string
+string
+EOD;
+    public const FOO = <<<'EOD'
+string
+string
+string
+EOD;
+
+    public function test($var = <<<'EOD'
+string
+string
+string
+EOD
+    ) {
+    }
+    public function test1($var, $var = <<<'EOD'
+string
+string
+string
+EOD
+    ) {
+    }
+    public function test2($var = <<<'EOD'
+string
+string
+string
+EOD
+        ,
+      $var
+    ) {
+    }
+}
+
+declare(ticks=1) {
+    <<<'EOD'
+string
+string
+string
+EOD;
+    $str = <<<'EOD'
+string
+string
+string
+EOD;
+}
+
+function foo() {
+    <<<'EOD'
+string
+string
+string
+EOD;
+    $str = <<<'EOD'
+string
+string
+string
+EOD;
+}
+
+$var = function () {
+    <<<'EOD'
+string
+string
+string
+EOD;
+    $str = <<<'EOD'
+string
+string
+string
+EOD;
+};
+
+$a = [
+    <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+];
+
+$a = [
+    $a,
+    <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    $a
+];
+
+$a = [
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+    ,
+];
+
+$a = [
+    'other-key' => $a,
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+];
+
+$a = [
+    'key' => <<<'EOD'
+string
+string
+string
+EOD
+    ,
+    'other-key' => $a
+];
+
+switch ($i) {
+    case <<<'TXT'
+string
+TXT
+    :
+        print <<<'TXT'
+string
+TXT;
+        break;
+
+    case <<<'TXT'
+other
+TXT
+    :
+        break;
+    default:
+        print <<<'TXT'
+string
+TXT;
+}
+
+