Skip to content

Commit 2981201

Browse files
author
Declan Vong
authored
fix: array expr - prefer single line - add missing comment check for multiline (#322)
1 parent 2bce58d commit 2981201

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

dprint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Users/declan/dprint

src/parsing/parser.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5994,8 +5994,11 @@ fn parse_array_like_nodes<'a>(opts: ParseArrayLikeNodesOptions<'a>, context: &mu
59945994
return items;
59955995

59965996
fn get_force_use_new_lines(node: &dyn Spanned, nodes: &[NodeOrSeparator], prefer_single_line: bool, context: &mut Context) -> bool {
5997-
if prefer_single_line || nodes.is_empty() {
5997+
if nodes.is_empty() {
59985998
false
5999+
} else if prefer_single_line {
6000+
// if any comments exist on separate lines, then everything becomes multi-line
6001+
has_any_node_comment_on_different_line(nodes, context)
59996002
} else {
60006003
let open_bracket_token = node
60016004
.tokens_fast(context.program)

tests/specs/expressions/ArrayExpression/ArrayExpression_PreferSingleLine_True.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,26 @@ const t = [5, 6];
1313
const t = [5, // testing
1414
6];
1515

16+
const a = [
17+
["123456", "123456"], //
18+
["123456", "123456"], //
19+
["123456", "123456"], //
20+
["123456", "123456"], //
21+
];
22+
1623
[expect]
1724
const t = [
1825
5, // testing
1926
6,
2027
];
2128

29+
const a = [
30+
["123456", "123456"], //
31+
["123456", "123456"], //
32+
["123456", "123456"], //
33+
["123456", "123456"], //
34+
];
35+
2236
== should not be multi line if the objects are allowed to be inline multi-line ==
2337
const t = [{
2438
prop: 5

0 commit comments

Comments
 (0)