plugin-ruby icon indicating copy to clipboard operation
plugin-ruby copied to clipboard

Non-stable formatting with a multi-line comment in a method chain

Open mharris-figma opened this issue 2 years ago • 1 comments

Using prettier 3.2.4 and version 4.0.4 of @pretter/plugin-ruby

The following code snippet:

invites =
  Invite
  .where(id: invite_ids)
  .where(redeemed_at: nil)
  # this is a
  # multi-line-comment
  .limit(20)

Gets formatted as:

invites =
  Invite
    .where(id: invite_ids)
    .where(redeemed_at: nil)# this is a
    # multi-line-comment
    .
    limit(20)

However, this formatting is unstable. When formatting is applied again, it changes to:

invites =
  Invite
    .where(id: invite_ids)
    .where(redeemed_at: nil) # this is a# multi-line-comment
    .
    limit(20)

And then an additional round of formatting results in:

invites =
  Invite
    .where(id: invite_ids)
    .where(redeemed_at: nil) # this is a# multi-line-comment
    .limit(20)

Which is finally stable.

In particular, I hit this when upgrading my codebase from version 1.6.1 of @pretter-plugin-ruby.

The original formatting seems the best?

mharris-figma avatar Jan 24 '24 17:01 mharris-figma

The same is true for single-line comments as well. I just got bit by this.

Just a friendly ping to @kddnewton. :smile:

boris-petrov avatar May 30 '24 02:05 boris-petrov