Skip to content

fix: keep an array expanded with preferSingleLine when a value on its own line is multi-line - #914

Merged
dsherret merged 2 commits into
mainfrom
fix-array-prefer-single-line-call-stability
Nov 10, 2026
Merged

dsherret merged 2 commits into
mainfrom
fix-array-prefer-single-line-call-stability

Conversation

@dsherret

Copy link
Copy Markdown
Member

Fixes output that changed when formatted a second time with arrayExpression.preferSingleLine: true. At lineWidth: 40:

const t = [call(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbb)];

was formatted as:

const t = [
    call(
        aaaaaaaaaaaaaaaaaaaaaaa,
        bbbbbbbbbbbbbbbbbbbbbbbbbbb,
    ),
];

and formatting that again gave:

const t = [call(
    aaaaaaaaaaaaaaaaaaaaaaa,
    bbbbbbbbbbbbbbbbbbbbbbbbbbb,
)];

With preferSingleLine, the newline after the open bracket doesn't make the array multi-line, and the arguments keep their line breaks, so the second time [call( fits on the first line and the call went beside the brackets. Now the first output is kept, which is also what happens without preferSingleLine. An array written expanded still collapses when it fits on one line, and a multi-line value written beside the brackets stays there.

The same is fixed for tupleType.preferSingleLine and arrayPattern.preferSingleLine, and for the other values that move to their own line when too long (ex. new expressions, functions with long parameters).

Change to output that was stable

With preferSingleLine, an array written expanded with a value that's always multi-line now stays expanded. For example, this used to go beside the brackets as [function() {:

const t = [
    function() {
        test;
    },
];

Object and array elements of an array expression still go beside the brackets as before.

Not fixed here

arguments.preferSingleLine and parameters.preferSingleLine have the same problem. Doing the same there would stop a callback written on its own line from going beside the parens, so I left that alone.

@dsherret
dsherret merged commit 2ccb312 into main Nov 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant