dprint-plugin-typescript icon indicating copy to clipboard operation
dprint-plugin-typescript copied to clipboard

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

Open declanvong opened this issue 2 years ago • 0 comments

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

declanvong avatar Dec 20 '22 12:12 declanvong