Skip to content

Commit 18706de

Browse files
authored
fix(attributes): remove extra line break (#1890)
Fixes #1884
1 parent 491a5fe commit 18706de

3 files changed

Lines changed: 8 additions & 13 deletions

File tree

src/printer.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,14 +1214,14 @@ function printAttrs(path, options, print, { inline = false } = {}) {
12141214
}
12151215
path.each((agPath) => {
12161216
const attrGroup = ["#["];
1217-
if (allAttrs.length > 0) {
1218-
allAttrs.push(inline ? " " : hardline);
1217+
if (!inline && allAttrs.length > 0) {
1218+
allAttrs.push(hardline);
12191219
}
1220-
attrGroup.push(ifBreak(softline));
1220+
attrGroup.push(softline);
12211221
agPath.each((attrPath) => {
12221222
const attrNode = attrPath.getValue();
12231223
if (attrGroup.length > 2) {
1224-
attrGroup.push(",", ifBreak(softline, " "));
1224+
attrGroup.push(",", line);
12251225
}
12261226
const attrStmt = [attrNode.name];
12271227
if (attrNode.args.length > 0) {
@@ -1234,10 +1234,9 @@ function printAttrs(path, options, print, { inline = false } = {}) {
12341234
concat([
12351235
indent(concat(attrGroup)),
12361236
ifBreak(shouldPrintComma(options, "8.0") ? "," : ""),
1237-
ifBreak(softline),
1238-
"]",
12391237
softline,
1240-
inline ? " " : "",
1238+
"]",
1239+
inline ? ifBreak(softline, " ") : "",
12411240
])
12421241
)
12431242
);

tests/attributes-trail-comma/__snapshots__/jsfmt.spec.js.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ final class ORM
4040
),
4141
X,
4242
]
43-
4443
final class ORM
4544
{
4645
#[
@@ -49,7 +48,6 @@ final class ORM
4948
ORM\\GeneratedValue(strategy: "CUSTOM"),
5049
ORM\\Id,
5150
]
52-
5351
private string $id;
5452
}
5553

tests/attributes/__snapshots__/jsfmt.spec.js.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class D
8181
*/
8282
#[I, J]
8383
function k(#[L] int $m): callable {
84-
return #[N, O] #[P] fn(#[Q] int $r) => $r * 2;
84+
return #[N, O] #[P] fn(#[Q] int $r) => $r * 2;
8585
} //Testing T
8686
8787
// Testing S
@@ -110,15 +110,14 @@ class D
110110
),
111111
X
112112
]
113-
114113
function Y(
115114
#[
116115
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ(
117116
12345678,
118117
1234578
119118
)
120119
]
121-
string $_
120+
string $_
122121
): string {
123122
return new #[NON, Anon] class {};
124123
}
@@ -127,7 +126,6 @@ function Y(
127126
IA("interface"),
128127
\\Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong\\Namespace\\WithStuff\\IB
129128
]
130-
131129
interface IC
132130
{
133131
#[ID]

0 commit comments

Comments
 (0)