Skip to content

Conversation

declanvong
Copy link

@declanvong declanvong commented Feb 22, 2023

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.

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