Repository: prettier/plugin-php
Pull request #591 (2018-09-10 10:09:49)

feat: support trailing comma in `use` node

evilebottnawi: Feel free to feedback :+1: 

Patch:
diff --git a/src/printer.js b/src/printer.js
index 1adfc4a..dcd9be5 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1752,7 +1752,13 @@ function printNode(path, options, print) {
               )
             ])
           ),
-          node.name ? concat([softline, "}"]) : ""
+          node.name
+            ? concat([
+                ifBreak(shouldPrintComma(options) ? "," : ""),
+                softline,
+                "}"
+              ])
+            : ""
         ])
       );
     case "useitem":


Test patch:
diff --git a/tests/trailing_commas/__snapshots__/jsfmt.spec.js.snap b/tests/trailing_commas/__snapshots__/jsfmt.spec.js.snap
index cc221ab..5b6330f 100644
--- a/tests/trailing_commas/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/trailing_commas/__snapshots__/jsfmt.spec.js.snap
@@ -311,3 +311,89 @@ list(
 ) = $arr;
 
 `;
+
+exports[`use.php 1`] = `
+<?php
+
+use foo\\bar\\{ClassA, ClassB, ClassC,};
+use function foo\\bar\\{fn_a, fn_b, fn_c,};
+use const foo\\bar\\{ConstA, ConstB, ConstC,};
+use other_foo\\bar\\{ClassA, ClassB, ClassC as C,};
+
+use foo\\bar\\{VeryVeryVeryVeryVeryLongClassA, VeryVeryVeryVeryVeryLongClassB, VeryVeryVeryVeryVeryLongClassC,};
+use function foo\\bar\\{very_very_very_very_very_long_fn_a, very_very_very_very_very_long_fn_b, very_very_very_very_very_long_fn_c,};
+use const foo\\bar\\{VeryVeryVeryVeryVeryLongConstA, VeryVeryVeryVeryVeryLongConstB, VeryVeryVeryVeryVeryLongConstC,};
+use other_foo\\bar\\{VeryVeryVeryVeryVeryLongClassA, VeryVeryVeryVeryVeryLongClassB, VeryVeryVeryVeryVeryLongClassC as C,};
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+
+use foo\\bar\\{ClassA, ClassB, ClassC};
+use function foo\\bar\\{fn_a, fn_b, fn_c};
+use const foo\\bar\\{ConstA, ConstB, ConstC};
+use other_foo\\bar\\{ClassA, ClassB, ClassC as C};
+
+use foo\\bar\\{
+    VeryVeryVeryVeryVeryLongClassA,
+    VeryVeryVeryVeryVeryLongClassB,
+    VeryVeryVeryVeryVeryLongClassC
+};
+use function foo\\bar\\{
+    very_very_very_very_very_long_fn_a,
+    very_very_very_very_very_long_fn_b,
+    very_very_very_very_very_long_fn_c
+};
+use const foo\\bar\\{
+    VeryVeryVeryVeryVeryLongConstA,
+    VeryVeryVeryVeryVeryLongConstB,
+    VeryVeryVeryVeryVeryLongConstC
+};
+use other_foo\\bar\\{
+    VeryVeryVeryVeryVeryLongClassA,
+    VeryVeryVeryVeryVeryLongClassB,
+    VeryVeryVeryVeryVeryLongClassC as C
+};
+
+`;
+
+exports[`use.php 2`] = `
+<?php
+
+use foo\\bar\\{ClassA, ClassB, ClassC,};
+use function foo\\bar\\{fn_a, fn_b, fn_c,};
+use const foo\\bar\\{ConstA, ConstB, ConstC,};
+use other_foo\\bar\\{ClassA, ClassB, ClassC as C,};
+
+use foo\\bar\\{VeryVeryVeryVeryVeryLongClassA, VeryVeryVeryVeryVeryLongClassB, VeryVeryVeryVeryVeryLongClassC,};
+use function foo\\bar\\{very_very_very_very_very_long_fn_a, very_very_very_very_very_long_fn_b, very_very_very_very_very_long_fn_c,};
+use const foo\\bar\\{VeryVeryVeryVeryVeryLongConstA, VeryVeryVeryVeryVeryLongConstB, VeryVeryVeryVeryVeryLongConstC,};
+use other_foo\\bar\\{VeryVeryVeryVeryVeryLongClassA, VeryVeryVeryVeryVeryLongClassB, VeryVeryVeryVeryVeryLongClassC as C,};
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+
+use foo\\bar\\{ClassA, ClassB, ClassC};
+use function foo\\bar\\{fn_a, fn_b, fn_c};
+use const foo\\bar\\{ConstA, ConstB, ConstC};
+use other_foo\\bar\\{ClassA, ClassB, ClassC as C};
+
+use foo\\bar\\{
+    VeryVeryVeryVeryVeryLongClassA,
+    VeryVeryVeryVeryVeryLongClassB,
+    VeryVeryVeryVeryVeryLongClassC,
+};
+use function foo\\bar\\{
+    very_very_very_very_very_long_fn_a,
+    very_very_very_very_very_long_fn_b,
+    very_very_very_very_very_long_fn_c,
+};
+use const foo\\bar\\{
+    VeryVeryVeryVeryVeryLongConstA,
+    VeryVeryVeryVeryVeryLongConstB,
+    VeryVeryVeryVeryVeryLongConstC,
+};
+use other_foo\\bar\\{
+    VeryVeryVeryVeryVeryLongClassA,
+    VeryVeryVeryVeryVeryLongClassB,
+    VeryVeryVeryVeryVeryLongClassC as C,
+};
+
+`;
diff --git a/tests/trailing_commas/use.php b/tests/trailing_commas/use.php
new file mode 100644
index 0000000..e97ff6a
--- /dev/null
+++ b/tests/trailing_commas/use.php
@@ -0,0 +1,11 @@
+<?php
+
+use foo\bar\{ClassA, ClassB, ClassC,};
+use function foo\bar\{fn_a, fn_b, fn_c,};
+use const foo\bar\{ConstA, ConstB, ConstC,};
+use other_foo\bar\{ClassA, ClassB, ClassC as C,};
+
+use foo\bar\{VeryVeryVeryVeryVeryLongClassA, VeryVeryVeryVeryVeryLongClassB, VeryVeryVeryVeryVeryLongClassC,};
+use function foo\bar\{very_very_very_very_very_long_fn_a, very_very_very_very_very_long_fn_b, very_very_very_very_very_long_fn_c,};
+use const foo\bar\{VeryVeryVeryVeryVeryLongConstA, VeryVeryVeryVeryVeryLongConstB, VeryVeryVeryVeryVeryLongConstC,};
+use other_foo\bar\{VeryVeryVeryVeryVeryLongClassA, VeryVeryVeryVeryVeryLongClassB, VeryVeryVeryVeryVeryLongClassC as C,};