Skip to content

Commit 63729fd

Browse files
authored
fix: correct formatting comment after tailing comma on single line with "trailingCommas": "always" (#449)
1 parent c5ac37c commit 63729fd

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ serde_json = { version = "1.0", optional = true }
3434

3535
[dev-dependencies]
3636
debug-here = "0.2"
37-
dprint-development = "0.9.1"
37+
dprint-development = "0.9.2"
3838
serde_json = { version = "1.0" }

src/generation/generate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7050,6 +7050,7 @@ where
70507050
Signal::NewLine.into(),
70517051
));
70527052
} else {
7053+
let last_comma_token = nodes.last().and_then(|n| context.token_finder.get_next_token_if_comma(n));
70537054
items.extend(gen_separated_values(
70547055
GenSeparatedValuesParams {
70557056
nodes: nodes.into_iter().map(NodeOrSeparator::Node).collect(),
@@ -7066,6 +7067,10 @@ where
70667067
},
70677068
context,
70687069
));
7070+
// the comma may disappear, so generate any trailing comments on the same line
7071+
if let Some(last_comma_token) = last_comma_token {
7072+
items.extend(gen_trailing_comments_same_line(&last_comma_token.range(), context));
7073+
}
70697074
}
70707075

70717076
items

tests/specs/general/Parameters_All.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,27 @@ export async function acceptWebSocket(req = {
7070
other: 7,
7171
}): Promise<WebSocket> {
7272
}
73+
74+
== should keep comment and remove trailing comma on single line ==
75+
function test(test, /* test */) {
76+
}
77+
78+
[expect]
79+
function test(test /* test */) {
80+
}
81+
82+
== should handle comments on next line ==
83+
function test(
84+
test, /* test */
85+
/* test */
86+
// test
87+
) {
88+
}
89+
90+
[expect]
91+
function test(
92+
test, /* test */
93+
/* test */
94+
// test
95+
) {
96+
}

tests/specs/issues/issue0440.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
~~ indentWidth: 2, quoteStyle: alwaysSingle, semiColons: always, trailingCommas: always ~~
2+
== should handle comment in place of parameter ==
3+
function hasDeepProp(target /* , param1, param2, ... */) {
4+
}
5+
6+
function hasDeepProp(target, /* , param1, param2, ... */) {
7+
}
8+
9+
[expect]
10+
function hasDeepProp(target, /* , param1, param2, ... */) {
11+
}
12+
13+
function hasDeepProp(target, /* , param1, param2, ... */) {
14+
}

0 commit comments

Comments
 (0)