Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

union types: fix trailing comment causing multiline when preferSingleLine is true #496

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

declanvong
Copy link
Contributor

@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.

None yet

1 participant