Skip to content

preferSingleLine sometimes doesn't collapse arguments, until a comment is added #459

Closed

Description

@declanvong

Describe the bug

dprint-plugin-typescript version: 0.79.0

The following has two sets of input code that are identical except for the addition of a comment above <Component in the second one. (Note that the comment can be completely blank, the length doesn't matter).

However, the second one is (correctly) collapsed, while the first one isn't. I would expect both to be formatted the same, except for the addition of the comment. This only happens when preferSingleLine is enabled, and I'd expect it to be collapsed like the second one.

Input Code

Array.from(
    { length: 1 },
    (_, i) => (
        <Component
            prop1={somePropFooBlah}
            prop2={`Some string here askdjalskdjalskdjlaskjd`}
            prop3={[1, 2, 3, 4]}
        />
    ),
);

Array.from(
    { length: 1 },
    (_, i) => (
        // hi
        <Component
            prop1={somePropFooBlah}
            prop2={`Some string here askdjalskdjalskdjlaskjd`}
            prop3={[1, 2, 3, 4]}
        />
    ),
);

Expected Output

Both same, but one with a comment.

Actual Output

Array.from(
  { length: 1 },
  (_, i) => (
    <Component
      prop1={somePropFooBlah}
      prop2={`Some string here askdjalskdjalskdjlaskjd`}
      prop3={[1, 2, 3, 4]}
    />
  ),
);

Array.from({ length: 1 }, (_, i) => (
  // hi
  <Component
    prop1={somePropFooBlah}
    prop2={`Some string here askdjalskdjalskdjlaskjd`}
    prop3={[1, 2, 3, 4]}
  />
));

Playground link here

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions