dprint-plugin-typescript
dprint-plugin-typescript copied to clipboard
union types: fix trailing comment causing multiline when preferSingleLine is true
has_any_node_comment_on_different_line
doesn't currently consider the case where the final node has a trailing line comment (which is therefore on the same line).
This causes issues such as the following, where we see union types randomly get multi-lined when we add a trailing comment:
Input:
function f(
arg: '1' | '2',
otherArg: string,
) { }
add a // todo: fix me
after arg: '1' | '2',
Output:
function f(
arg:
| '1'
| '2', // todo: fix me
otherArg: string,
) { }
Expected:
function f(
arg: '1' | '2', // todo: fix me
otherArg: string,
) { }
This PR fixes that by allowing a trailing line comment for the last node in the node list.
I've added tests for this case (union / intersection types), and these are the the most obvious cases I've seen so far, but it's probable that this affects many other collections as well.