Repository: prettier/plugin-php
Pull request #2412 (2025-01-08 10:51:52)

fix: parameter comment function attribute removal
The title may sound a bit confusing, but what essentially happened was a function attribute deletion on formatting when one of the parameters has a line comment afterward its declaration.

An example of said behaviour can be seen [here](https://loilo.github.io/prettier-php-playground/#N4IgDgTgpgLjCWUIHkwIPYDsDOIBcok8mMA6vACYwAW+AHAAwA0IMAhgEblW14AsLAK7YoAFU648AMzYAbES2zEA5rKgBFQehhR8M+VBZhqYAGpIlWfCDoA6AEwgWMCG3iyVAYXQBbH2wAFAAkA-BdBQxAOVwBjKABlGABPNWswJABaGNwWaABHQXhoANdlfz05BRBiEQgYErYytgqDAF8WKAp4GHQUNHgsSVA2bBgWkXbqzDBBMbwQAB4AfmMwAB1MDYBiAG0AQTW1gCEAXQ2pQUwYjEwAAil0dAAKDdvb4hhbgBI2JluAen+txo8Gwtxivh8UBI4LYwigYLYcAg8A4sygwPQty62GwbDA6TYEFe7xhXw4TA2AEpbsASdAYIIIHcfrcANTfDgAbg2rQ2IFaQA)


Patch:
diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml
index 1851700..256a267 100644
--- a/.github/workflows/nodejs.yml
+++ b/.github/workflows/nodejs.yml
@@ -45,7 +45,7 @@ jobs:
           cache: "yarn"
       - run: yarn install --frozen-lockfile
       - run: yarn c8 yarn test:node
-      - uses: codecov/codecov-action@v3
+      - uses: codecov/codecov-action@v5
         with:
           token: ${{ secrets.CODECOV_TOKEN }}
           fail_ci_if_error: true
diff --git a/package.json b/package.json
index 5bb4005..51a1155 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@prettier/plugin-php",
-  "version": "0.22.2",
+  "version": "0.22.3",
   "description": "Prettier PHP Plugin",
   "repository": "prettier/prettier-php",
   "author": "Lucas Azzola <@azz>",
diff --git a/src/printer.mjs b/src/printer.mjs
index 066b68f..cec72d0 100644
--- a/src/printer.mjs
+++ b/src/printer.mjs
@@ -1410,7 +1410,7 @@ function printFunction(path, options, print) {
   const willBreakDeclaration = declaration.some(willBreak);
 
   if (willBreakDeclaration) {
-    return [printedDeclaration, " ", printedBody];
+    return [...declAttrs, printedDeclaration, " ", printedBody];
   }
 
   return [


Test patch:
diff --git a/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap b/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap
index 16622e7..7d30d00 100644
--- a/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap
+++ b/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap
@@ -90,6 +90,28 @@ class Test
     }
 
 }
+
+class ParamCommentFunctionAnnotation {
+
+    #[Foo]
+    function bar(
+        int $a, // parameter comment
+        int $b,
+    ) {
+        return $a + $b;
+    }
+
+    #[Foo]
+    function bar2(
+        int $a,
+        int $middle, // parameter comment
+        int $b,
+    ) {
+        return $a + $middle + $b;
+    }
+
+}
+
 =====================================output=====================================
 <?php
 
@@ -206,5 +228,25 @@ class Test
     }
 }
 
+class ParamCommentFunctionAnnotation
+{
+    #[Foo]
+    function bar(
+        int $a, // parameter comment
+        int $b
+    ) {
+        return $a + $b;
+    }
+
+    #[Foo]
+    function bar2(
+        int $a,
+        int $middle, // parameter comment
+        int $b
+    ) {
+        return $a + $middle + $b;
+    }
+}
+
 ================================================================================
 `;
diff --git a/tests/attributes/attributes.php b/tests/attributes/attributes.php
index 9c899cb..bb93d75 100644
--- a/tests/attributes/attributes.php
+++ b/tests/attributes/attributes.php
@@ -81,4 +81,25 @@ class Test
         return $foo;
     }
 
-}
\ No newline at end of file
+}
+
+class ParamCommentFunctionAnnotation {
+
+    #[Foo]
+    function bar(
+        int $a, // parameter comment
+        int $b,
+    ) {
+        return $a + $b;
+    }
+
+    #[Foo]
+    function bar2(
+        int $a,
+        int $middle, // parameter comment
+        int $b,
+    ) {
+        return $a + $middle + $b;
+    }
+
+}