nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: prettier/plugin-php
Pull request #748 (2018-10-08 16:50:08)

fix: comments in empty parens
Logic from prettier

evilebottnawi: Feel free to feedback

Patch:
diff --git a/src/comments.js b/src/comments.js
index f19e394..a2cab9f 100644
--- a/src/comments.js
+++ b/src/comments.js
@@ -357,12 +357,25 @@ function handleHalt(enclosingNode, precedingNode, comment) {
   return false;
 }
 
-function handleCommentInEmptyParens(text, enclosingNode, comment) {
+function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
+  const nextCharIndex = getNextNonSpaceNonCommentCharacterIndex(
+    text,
+    comment,
+    options
+  );
+
+  if (text.charAt(nextCharIndex) !== ")") {
+    return false;
+  }
+
   // Only add dangling comments to fix the case when no arguments are present,
   // i.e. a function without any argument.
   if (
     enclosingNode &&
-    (enclosingNode.kind === "closure" ||
+    (enclosingNode.kind === "function" ||
+      enclosingNode.kind === "closure" ||
+      enclosingNode.kind === "method" ||
+      enclosingNode.kind === "closure" ||
       enclosingNode.kind === "call" ||
       enclosingNode.kind === "new") &&
     enclosingNode.arguments.length === 0


Test patch:
diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap
index 5534aac..86989d4 100644
--- a/tests/comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap
@@ -1351,9 +1351,8 @@ function foo($a): /* 5 */ ?string /* 6 */
 function foo(/* 1 */ $a /* 2 */ = /* 3 */ 1 /* 4 */): /* 5 */ ?string /* 6 */
 {
 }
-function emptyFn()
+function emptyFn(/*Comment */)
 {
-    /*Comment */
 }
 
 `;
@@ -2057,6 +2056,8 @@ class Foo {
 
     public function emptyMethod(/* comments */) {}
 
+    abstract public function sortByName(/* bool $useNaturalSort = false */);
+
     /* comment */ protected /* comment */ static /* comment */ $foo /* comment */;
 }
 
@@ -2085,10 +2086,11 @@ class Foo
     ): /* 5 */ ?string /* 6 */ {
     }
 
-    public function emptyMethod()
+    public function emptyMethod(/* comments */)
     {
-        /* comments */
-    } /* comment */
+    }
+
+    abstract public function sortByName(/* bool $useNaturalSort = false */); /* comment */
 
     /* comment */ /* comment */ protected static $foo; /* comment */
 }
diff --git a/tests/comments/method.php b/tests/comments/method.php
index 9f57988..148d3bf 100644
--- a/tests/comments/method.php
+++ b/tests/comments/method.php
@@ -5,6 +5,8 @@ class Foo {
 
     public function emptyMethod(/* comments */) {}
 
+    abstract public function sortByName(/* bool $useNaturalSort = false */);
+
     /* comment */ protected /* comment */ static /* comment */ $foo /* comment */;
 }
Repository: prettier/plugin-php
Pull request #756 (2018-10-09 13:59:09)

fix: indent for `print` node with end of line comment
Looks we forget about this problem :smile: 

evilebottnawi: Feel free to feedback

Patch:
diff --git a/src/printer.js b/src/printer.js
index 69b3725..b6f9f82 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -2065,7 +2065,12 @@ function printNode(path, options, print) {
       );
     }
     case "print": {
-      return concat(["print ", path.call(print, "arguments")]);
+      return concat([
+        "print ",
+        node.arguments.comments
+          ? indent(path.call(print, "arguments"))
+          : path.call(print, "arguments")
+      ]);
     }
     case "return": {
       const parts = [];


Test patch:
diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap
index 2a4df55..a883c2a 100644
--- a/tests/comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap
@@ -2507,15 +2507,46 @@ print // Comment
     ;
 
 print /* Comment */ $foo /* Comment */;
+
+print // Comment
+    $a;
+
+print (// Comment
+    $a
+);
+
+print call(
+    // Comment
+    $a
+);
+
+print // Comment
+    // Comment
+    $a;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
 print // Comment
-$foo;
-/* Comment */
+    $foo;
+    /* Comment */
 
 print /* Comment */ $foo /* Comment */;
 
+print // Comment
+    $a;
+
+print // Comment
+    $a;
+
+print call(
+    // Comment
+    $a
+);
+
+print // Comment
+    // Comment
+    $a;
+
 `;
 
 exports[`property.php - php-verify: property.php 1`] = `
diff --git a/tests/comments/print.php b/tests/comments/print.php
index 303209a..018eeca 100644
--- a/tests/comments/print.php
+++ b/tests/comments/print.php
@@ -6,3 +6,19 @@ print // Comment
     ;
 
 print /* Comment */ $foo /* Comment */;
+
+print // Comment
+    $a;
+
+print (// Comment
+    $a
+);
+
+print call(
+    // Comment
+    $a
+);
+
+print // Comment
+    // Comment
+    $a;
Repository: prettier/plugin-php
Pull request #759 (2018-10-09 14:43:58)

fix: indent for `clone` node with end of line comment


Patch:
diff --git a/src/printer.js b/src/printer.js
index 2553500..a6f4f35 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1883,7 +1883,12 @@ function printNode(path, options, print) {
       );
     }
     case "clone":
-      return concat(["clone ", path.call(print, "what")]);
+      return concat([
+        "clone ",
+        node.what.comments
+          ? indent(path.call(print, "what"))
+          : path.call(print, "what")
+      ]);
     case "propertylookup":
     case "staticlookup":
     case "offsetlookup": {


Test patch:
diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap
index 4bf9bb9..4302a63 100644
--- a/tests/comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap
@@ -847,11 +847,17 @@ exports[`clone.php - php-verify: clone.php 1`] = `
 <?php
 
 $obj2 = clone /* Comments */ $obj /* Comments */;
+
+$obj2 = clone // Comment
+    $obj;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
 $obj2 = clone /* Comments */ $obj /* Comments */;
 
+$obj2 = clone // Comment
+    $obj;
+
 `;
 
 exports[`closure.php - php-verify: closure.php 1`] = `
diff --git a/tests/comments/clone.php b/tests/comments/clone.php
index 810180c..380fb77 100644
--- a/tests/comments/clone.php
+++ b/tests/comments/clone.php
@@ -1,3 +1,6 @@
 <?php
 
 $obj2 = clone /* Comments */ $obj /* Comments */;
+
+$obj2 = clone // Comment
+    $obj;
Repository: prettier/plugin-php
Pull request #760 (2018-10-09 14:54:49)

test: `usegroup` node comment
Just test


Patch:
diff --git a/src/printer.js b/src/printer.js
index 2553500..a6f4f35 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1883,7 +1883,12 @@ function printNode(path, options, print) {
       );
     }
     case "clone":
-      return concat(["clone ", path.call(print, "what")]);
+      return concat([
+        "clone ",
+        node.what.comments
+          ? indent(path.call(print, "what"))
+          : path.call(print, "what")
+      ]);
     case "propertylookup":
     case "staticlookup":
     case "offsetlookup": {


Test patch:
diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap
index 4bf9bb9..0113fa2 100644
--- a/tests/comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap
@@ -847,11 +847,17 @@ exports[`clone.php - php-verify: clone.php 1`] = `
 <?php
 
 $obj2 = clone /* Comments */ $obj /* Comments */;
+
+$obj2 = clone // Comment
+    $obj;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
 $obj2 = clone /* Comments */ $obj /* Comments */;
 
+$obj2 = clone // Comment
+    $obj;
+
 `;
 
 exports[`closure.php - php-verify: closure.php 1`] = `
@@ -3058,6 +3064,9 @@ use /* Comment */ some\\namespaces\\/* Comment */{
     /* Comment */ ClassB/* Comment */,
     /* Comment */ ClassC /* Comment */ as /* Comment */ C
 };
+
+use // Comment
+    My\\Full\\NSname;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -3068,6 +3077,9 @@ use some\\namespaces\\{
     /* Comment */ as C
 };
 
+use // Comment
+    My\\Full\\NSname;
+
 `;
 
 exports[`variable.php - php-verify: variable.php 1`] = `
diff --git a/tests/comments/clone.php b/tests/comments/clone.php
index 810180c..380fb77 100644
--- a/tests/comments/clone.php
+++ b/tests/comments/clone.php
@@ -1,3 +1,6 @@
 <?php
 
 $obj2 = clone /* Comments */ $obj /* Comments */;
+
+$obj2 = clone // Comment
+    $obj;
diff --git a/tests/comments/usegroup.php b/tests/comments/usegroup.php
index a54fa1e..2699775 100644
--- a/tests/comments/usegroup.php
+++ b/tests/comments/usegroup.php
@@ -5,3 +5,6 @@ use /* Comment */ some\namespaces\/* Comment */{
     /* Comment */ ClassB/* Comment */,
     /* Comment */ ClassC /* Comment */ as /* Comment */ C
 };
+
+use // Comment
+    My\Full\NSname;
Repository: prettier/plugin-php
Pull request #762 (2018-10-09 15:11:52)

fix: indent for `throw` node with end of line comment


Patch:
diff --git a/src/printer.js b/src/printer.js
index b434211..777b3d2 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -2015,7 +2015,12 @@ function printNode(path, options, print) {
       ]);
     }
     case "throw":
-      return concat(["throw ", path.call(print, "what")]);
+      return concat([
+        "throw ",
+        node.what.comments
+          ? indent(path.call(print, "what"))
+          : path.call(print, "what")
+      ]);
     case "silent":
       return concat(["@", path.call(print, "expr")]);
     case "halt":


Test patch:
diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap
index d8e9c7d..3ea269b 100644
--- a/tests/comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap
@@ -1573,10 +1573,25 @@ exports[`global.php - php-verify: global.php 1`] = `
 <?php
 
 global /* Comment */ $a /* Comment */, /* Comment */ $b /* Comment */;
+global // Comment
+    $a;
+global
+    // Comment
+    $a;
+global // Comment
+    $a,
+    $b;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
 global /* Comment */ $a /* Comment */, /* Comment */ $b /* Comment */;
+global // Comment
+    $a;
+global // Comment
+    $a;
+global // Comment
+    $a,
+    $b;
 
 `;
 
@@ -2821,6 +2836,9 @@ throw new ClassName( /* Comment */
     /* Comment */
     /* Comment */ 2 /* Comment */
     /* Comment */); /* Comment */
+
+throw // Comment
+    new Exception();
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -2839,6 +2857,9 @@ throw new ClassName /* Comment */(
     /* Comment */
 ); /* Comment */
 
+throw // Comment
+    new Exception();
+
 `;
 
 exports[`trait.php - php-verify: trait.php 1`] = `
diff --git a/tests/comments/global.php b/tests/comments/global.php
index 6bce0c3..e673642 100644
--- a/tests/comments/global.php
+++ b/tests/comments/global.php
@@ -1,3 +1,11 @@
 <?php
 
 global /* Comment */ $a /* Comment */, /* Comment */ $b /* Comment */;
+global // Comment
+    $a;
+global
+    // Comment
+    $a;
+global // Comment
+    $a,
+    $b;
diff --git a/tests/comments/throw.php b/tests/comments/throw.php
index 981c9eb..ce15f27 100644
--- a/tests/comments/throw.php
+++ b/tests/comments/throw.php
@@ -13,3 +13,6 @@ throw new ClassName( /* Comment */
     /* Comment */
     /* Comment */ 2 /* Comment */
     /* Comment */); /* Comment */
+
+throw // Comment
+    new Exception();
Repository: prettier/plugin-php
Pull request #804 (2018-10-15 13:34:32)

fix: consistent break assign for static lookup
Add todo, when parser fix it we can remove this line


Patch:
diff --git a/src/printer.js b/src/printer.js
index 8df97f0..78d8fd1 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1383,7 +1383,11 @@ function isLookupNodeChain(node) {
     return false;
   }
 
-  if (["variable", "identifier"].includes(node.what.kind)) {
+  if (
+    ["variable", "identifier"].includes(node.what.kind) ||
+    // TODO: https://github.com/glayzzle/php-parser/issues/183
+    (node.what.kind === "constref" && node.what.name.toLowerCase() === "static")
+  ) {
     return true;
   }
 


Test patch:
diff --git a/tests/staticlookup/__snapshots__/jsfmt.spec.js.snap b/tests/staticlookup/__snapshots__/jsfmt.spec.js.snap
index 11a17a5..0ae0e2c 100644
--- a/tests/staticlookup/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/staticlookup/__snapshots__/jsfmt.spec.js.snap
@@ -102,6 +102,10 @@ $obj::$veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryV
 $var = ($this->modelClass)::where('name', 'like', strtoupper("%\${key}%"))->get();
 
 MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClass::class;
+
+$var = static::$arrayCache[$arrayStub->class][$arrayStub->position][$arrayStub->foo][$arrayStub->baz];
+$var = self::$arrayCache[$arrayStub->class][$arrayStub->position][$arrayStub->foo][$arrayStub->baz];
+$var = parent::$arrayCache[$arrayStub->class][$arrayStub->position][$arrayStub->foo][$arrayStub->baz];
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 Foo::aStaticMethod();
@@ -203,4 +207,20 @@ $var = $this->modelClass::where('name', 'like', strtoupper("%\${key}%"))->get();
 
 MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClass::class;
 
+$var =
+    static
+        ::$arrayCache[$arrayStub->class][$arrayStub->position][$arrayStub->foo][
+            $arrayStub->baz
+        ];
+$var =
+    self
+        ::$arrayCache[$arrayStub->class][$arrayStub->position][$arrayStub->foo][
+            $arrayStub->baz
+        ];
+$var =
+    parent
+        ::$arrayCache[$arrayStub->class][$arrayStub->position][$arrayStub->foo][
+            $arrayStub->baz
+        ];
+
 `;
diff --git a/tests/staticlookup/staticlookup.php b/tests/staticlookup/staticlookup.php
index bfb3e35..417dc3c 100644
--- a/tests/staticlookup/staticlookup.php
+++ b/tests/staticlookup/staticlookup.php
@@ -81,3 +81,7 @@ $obj::$veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryV
 $var = ($this->modelClass)::where('name', 'like', strtoupper("%${key}%"))->get();
 
 MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClass::class;
+
+$var = static::$arrayCache[$arrayStub->class][$arrayStub->position][$arrayStub->foo][$arrayStub->baz];
+$var = self::$arrayCache[$arrayStub->class][$arrayStub->position][$arrayStub->foo][$arrayStub->baz];
+$var = parent::$arrayCache[$arrayStub->class][$arrayStub->position][$arrayStub->foo][$arrayStub->baz];
Repository: prettier/plugin-php
Pull request #837 (2018-11-06 09:47:00)

fix: unstable function comments
Port from prettier

evilebottnawi: Feel free to feedback :+1: 

Patch:
diff --git a/src/comments.js b/src/comments.js
index 6b13afe..5142752 100644
--- a/src/comments.js
+++ b/src/comments.js
@@ -269,6 +269,17 @@ function handleLastFunctionArgComments(
     addTrailingComment(enclosingNode, comment);
     return true;
   }
+
+  if (
+    enclosingNode &&
+    (enclosingNode.kind === "function" || enclosingNode.kind === "method") &&
+    followingNode &&
+    followingNode.kind === "block"
+  ) {
+    addBlockStatementFirstComment(followingNode, comment);
+    return true;
+  }
+
   return false;
 }
 


Test patch:
diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap
index d9c26bf..b8ef701 100644
--- a/tests/comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap
@@ -2975,6 +2975,10 @@ function foo() {
     // this is a function
     return 42;
 }
+function foo // this is a function
+() {
+    return 42;
+}
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -3012,8 +3016,14 @@ function foo()
     // this is a function
     return 42;
 }
-function foo() // this is a function
+function foo()
 {
+    // this is a function
+    return 42;
+}
+function foo()
+{
+    // this is a function
     return 42;
 }
 function foo()
@@ -4277,6 +4287,11 @@ class Foo {
         // this is a function
         return 42;
     }
+
+    function foo // this is a function
+    () {
+        return 42;
+    }
 }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
@@ -4336,8 +4351,15 @@ class Foo
         return 42;
     }
 
-    function foo() // this is a function
+    function foo()
     {
+        // this is a function
+        return 42;
+    }
+
+    function foo()
+    {
+        // this is a function
         return 42;
     }
 
diff --git a/tests/comments/functions.php b/tests/comments/functions.php
index bc50474..4b3fa3c 100644
--- a/tests/comments/functions.php
+++ b/tests/comments/functions.php
@@ -34,3 +34,7 @@ function foo() {
     // this is a function
     return 42;
 }
+function foo // this is a function
+() {
+    return 42;
+}
diff --git a/tests/comments/method.php b/tests/comments/method.php
index 2fa9a3e..30fa0c7 100644
--- a/tests/comments/method.php
+++ b/tests/comments/method.php
@@ -60,4 +60,9 @@ class Foo {
         // this is a function
         return 42;
     }
+
+    function foo // this is a function
+    () {
+        return 42;
+    }
 }
Repository: prettier/plugin-php
Pull request #917 (2019-01-24 12:02:51)

fix: indent constructor in new with comment
Partial https://github.com/prettier/plugin-php/issues/844

evilebottnawi: Feel free to feedback, merge to continue development

Patch:
diff --git a/src/printer.js b/src/printer.js
index e28ada0..6e8ccd5 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -2007,20 +2007,28 @@ function printNode(path, options, print) {
         ]);
       }
 
-      const printedWhat = isAnonymousClassNode
-        ? concat([
-            "class",
-            node.arguments.length > 0
-              ? printArgumentsList(path, options, print)
-              : "",
-            group(path.call(print, "what"))
-          ])
-        : concat([
-            path.call(print, "what"),
-            printArgumentsList(path, options, print)
-          ]);
+      const parts = [];
+
+      parts.push("new ");
+
+      if (isAnonymousClassNode) {
+        parts.push(
+          "class",
+          node.arguments.length > 0
+            ? printArgumentsList(path, options, print)
+            : "",
+          group(path.call(print, "what"))
+        );
+      } else {
+        const printed = concat([
+          path.call(print, "what"),
+          printArgumentsList(path, options, print)
+        ]);
+
+        parts.push(hasLeadingComment(node.what) ? indent(printed) : printed);
+      }
 
-      return concat(["new ", printedWhat]);
+      return concat(parts);
     }
     case "clone":
       return concat([


Test patch:
diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap
index 46d711a..db85455 100644
--- a/tests/comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap
@@ -5769,7 +5769,7 @@ $a = new class() {
 $a = new Foo(/*Comment*/);
 $a = new Foo(/* Comment */ 1 /*Comments*/);
 $a = new // Comment
-Foo();
+    Foo();
 
 $a = new class// Comment
  {