Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/printer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,30 +1170,25 @@ function printAttrs(path, options, print, { inline = false } = {}) {
return [];
}
path.each(() => {
const attrGroup = ["#["];
const attrGroup = [];
if (!inline && allAttrs.length > 0) {
allAttrs.push(hardline);
}
attrGroup.push(softline);
path.each(() => {
path.each((_, index) => {
const attrNode = path.node;
if (attrGroup.length > 2) {
attrGroup.push(",", line);
}
const attrStmt = [attrNode.name];
if (attrNode.args.length > 0) {
attrStmt.push(printArgumentsList(path, options, print, "args"));
}
attrGroup.push(group(attrStmt));
if (index === 0) {
attrGroup.push("#[");
} else {
attrGroup.push(ifBreak([line, "#["], ", "));
}
attrGroup.push(group(attrStmt), ifBreak("]"));
}, "attrs");
allAttrs.push(
group([
indent(attrGroup),
ifBreak(shouldPrintComma(options, "8.0") ? "," : ""),
softline,
"]",
inline ? ifBreak(softline, " ") : "",
])
group([attrGroup, ifBreak("", "]"), inline ? ifBreak(softline, " ") : ""])
);
}, "attrGroups");
if (allAttrs.length === 0) {
Expand Down
36 changes: 16 additions & 20 deletions tests/attributes-trail-comma/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,24 @@ final class ORM
=====================================output=====================================
<?php

#[
W(
"a",
null,
"looooong",
"paraaaams",
"list",
"aaaaaaaaaaaaa",
"vvvvvvvvvvvv",
"cccccccccc",
"eeeeeeeeeee",
),
X,
]
#[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,
]
#[ORM\\Column]
#[ORM\\CustomIdGenerator(class: "bar")]
#[ORM\\GeneratedValue(strategy: "CUSTOM")]
#[ORM\\Id]
private string $id;
}

Expand Down
62 changes: 34 additions & 28 deletions tests/attributes/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ final class DomainEventMessage
}
}

// issue #2360
#[Route('route/path', name: 'very_very_very_very_very_very_long_route_name', methods: ['GET'])]
class Controller
{
}

#[
Attr1(Attr1::FOO | Attr1::BAR),
Attr2(-20 * 5 + 10)
Expand Down Expand Up @@ -148,36 +154,30 @@ class D
}
}

#[
W(
"a",
null,
"looooong",
"paraaaams",
"list",
"aaaaaaaaaaaaa",
"vvvvvvvvvvvv",
"cccccccccc",
"eeeeeeeeeee"
),
X
]
#[W(
"a",
null,
"looooong",
"paraaaams",
"list",
"aaaaaaaaaaaaa",
"vvvvvvvvvvvv",
"cccccccccc",
"eeeeeeeeeee"
)]
#[X]
function Y(
#[
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ(
12345678,
1234578
)
]
#[ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ(
12345678,
1234578
)]
string $_
): string {
return new #[NON, Anon] class {};
}

#[
IA("interface"),
\\Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong\\Namespace\\WithStuff\\IB
]
#[IA("interface")]
#[\\Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong\\Namespace\\WithStuff\\IB]
interface IC
{
#[ID]
Expand All @@ -202,15 +202,21 @@ final class DomainEventMessage
}
}

// issue #2360
#[Route(
"route/path",
name: "very_very_very_very_very_very_long_route_name",
methods: ["GET"]
)]
class Controller {}

#[Attr1(Attr1::FOO | Attr1::BAR), Attr2(-20 * 5 + 10)]
class A {}

class ValueModel
{
#[
Assert\\NotBlank(allowNull: false, groups: ["foo"]),
Assert\\Length(max: 255, groups: ["foo"])
]
#[Assert\\NotBlank(allowNull: false, groups: ["foo"])]
#[Assert\\Length(max: 255, groups: ["foo"])]
public ?string $value = null;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/attributes/attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public function getPayload1(): string
}
}

// issue #2360
#[Route('route/path', name: 'very_very_very_very_very_very_long_route_name', methods: ['GET'])]
class Controller
{
}

#[
Attr1(Attr1::FOO | Attr1::BAR),
Attr2(-20 * 5 + 10)
Expand Down
Loading