Skip to content

Situation where code formatting is not idempotent and creates really long comment #149

Open

Description

@devonpmack

Try formatting this code:

def foo(bar)
  Foo
    .where(
      id: bar
    )
    # The second condition helps to skip the newly create runtime stated as "initialized"
    # The first condition helps to skip the soft deleted runtime marked as "remote_deleted"
    #   that hasn't been appeared in ProdRegistry
    .where(<<-SQL)
        (foo)
      SQL
end
def foo(bar)
  Foo.where(
    id: bar
  )# The second condition helps to skip the newly create runtime stated as "initialized"
  # The first condition helps to skip the soft deleted runtime marked as "remote_deleted"
  #   that hasn't been appeared in ProdRegistry
  .
    where(<<-SQL)
        (foo)
      SQL
end
def foo(bar)
  Foo.where(
    id: bar
  )# The first condition helps to skip the soft deleted runtime marked as "remote_deleted" # The second condition helps to skip the newly create runtime stated as "initialized"
  #   that hasn't been appeared in ProdRegistry
  .
    where(<<-SQL)
        (foo)
      SQL
end
def foo(bar)
  Foo.where(id: bar)#   that hasn't been appeared in ProdRegistry # The first condition helps to skip the soft deleted runtime marked as "remote_deleted" # The second condition helps to skip the newly create runtime stated as "initialized"
  .
    where(<<-SQL)
        (foo)
      SQL
end
def foo(bar)
  Foo.where(id: bar) #   that hasn't been appeared in ProdRegistry # The first condition helps to skip the soft deleted runtime marked as "remote_deleted" # The second condition helps to skip the newly create runtime stated as "initialized"
    .where(<<-SQL)
        (foo)
      SQL
end

Activity

  1. changed the title [-]Situation where code formatting is not idempotent[/-] [+]Situation where code formatting is not idempotent and creates really long comment[/+] on Aug 25, 2022
  2. maxnotarangelo commented on Aug 29, 2023

    @maxnotarangelo

    I'm getting (presumably) the same bug when there's a comment between lines in a method chain:

    Original code:

    result = long_method_chain
      .something
      .something_else[0]
      .a_third_thing
      # the important one
      .a_fourth_thing

    After the first run:

    result =
      long_method_chain.something.something_else[0].a_third_thing# the important one
      .
        a_fourth_thing

    After the second run:

    result =
      long_method_chain.something.something_else[0].a_third_thing # the important one
        .a_fourth_thing

    Interestingly, if it's pure method calls, it does the nice-looking thing and is idempotent. Original:

    result = long_method_chain
      .something
      .something_else(0)
      .a_third_thing
      # the important one
      .a_fourth_thing

    After formatting:

    result =
      long_method_chain
        .something
        .something_else(0)
        .a_third_thing
        # the important one
        .a_fourth_thing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions