Skip to content

Commit

Permalink
added dangling commas on multiline attributes (#1886)
Browse files Browse the repository at this point in the history
fixes #1884
  • Loading branch information
cseufert authored Dec 17, 2021
1 parent f0e6add commit b730e64
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,9 @@ function printArgumentsList(path, options, print, argumentsKey = "arguments") {
(shouldPrintComma(options, "7.3") &&
["call", "new", "unset", "isset"].includes(node.kind)) ||
(shouldPrintComma(options, "8.0") &&
["function", "closure", "method", "arrowfunc"].includes(node.kind))
["function", "closure", "method", "arrowfunc", "attribute"].includes(
node.kind
))
? indent(
concat([
lastArg && shouldPrintHardlineBeforeTrailingComma(lastArg)
Expand Down Expand Up @@ -1231,6 +1233,7 @@ function printAttrs(path, options, print, { inline = false } = {}) {
group(
concat([
indent(concat(attrGroup)),
ifBreak(shouldPrintComma(options, "8.0") ? "," : ""),
ifBreak(softline),
"]",
softline,
Expand Down Expand Up @@ -2225,7 +2228,7 @@ function printNode(path, options, print) {
])
: "",
...path.call(
(pa, opt, pr) => printAttrs(pa, opt, pr, { inline: true }),
(pa) => printAttrs(pa, options, print, { inline: true }),
"what"
),
"class",
Expand Down
57 changes: 57 additions & 0 deletions tests/attributes-trail-comma/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`attributes-trail-comma.php 1`] = `
====================================options=====================================
parsers: ["php"]
phpVersion: "8.0"
printWidth: 80
trailingCommaPHP: true
| printWidth
=====================================input======================================
<?php
#[W('a', null, 'looooong','paraaaams','list','aaaaaaaaaaaaa','vvvvvvvvvvvv','cccccccccc','eeeeeeeeeee'), X()]
final class ORM
{
#[
ORM\\Column,
ORM\\CustomIdGenerator(class: "bar"),
ORM\\GeneratedValue(strategy: 'CUSTOM'),
ORM\\Id
]
private string $id;
}
=====================================output=====================================
<?php
#[
W(
"a",
null,
"looooong",
"paraaaams",
"list",
"aaaaaaaaaaaaa",
"vvvvvvvvvvvv",
"cccccccccc",
"eeeeeeeeeee",
),
X,
]
final class ORM
{
#[
ORM\\Column,
ORM\\CustomIdGenerator(class: "bar"),
ORM\\GeneratedValue(strategy: "CUSTOM"),
ORM\\Id,
]
private string $id;
}
================================================================================
`;
14 changes: 14 additions & 0 deletions tests/attributes-trail-comma/attributes-trail-comma.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

#[W('a', null, 'looooong','paraaaams','list','aaaaaaaaaaaaa','vvvvvvvvvvvv','cccccccccc','eeeeeeeeeee'), X()]
final class ORM
{

#[
ORM\Column,
ORM\CustomIdGenerator(class: "bar"),
ORM\GeneratedValue(strategy: 'CUSTOM'),
ORM\Id
]
private string $id;
}
1 change: 1 addition & 0 deletions tests/attributes-trail-comma/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, ["php"], { trailingCommaPHP: true, phpVersion: "8.0" });

0 comments on commit b730e64

Please sign in to comment.