Skip to content

formatting expressions with paren elision (?) is not idempotent #813

@froydnj

Description

@froydnj

Commit: dc86aa6

Input

→ View on rubyfmt.run

# initial input
module Amp
  def self.trim_team(team)
    {
      descendent_members: (team[:descendant_members].map { |v| self.trim_person } if team[descendant_members]
        .present?)
    }
  end
end

# output of formatting the above
module Amp
  def self.trim_team(team)
    {
      descendent_members: (if team[descendant_members].present?
        team[:descendant_members].map { |v| self.trim_person }
      end)
    }
  end
end

# output of formatting the above, which is
# - not idempotent
# - what formatting the first bit should have produced in the first place
module Amp
  def self.trim_team(team)
    {
      descendent_members: (
        if team[descendant_members].present?
          team[:descendant_members].map { |v| self.trim_person }
        end
      )
    }
  end
end

Output

# initial input
module Amp
  def self.trim_team(team)
    {
      descendent_members: (if team[descendant_members].present?
        team[:descendant_members].map { |v| self.trim_person }
      end)
    }
  end
end

# output of formatting the above
module Amp
  def self.trim_team(team)
    {
      descendent_members: (
        if team[descendant_members].present?
          team[:descendant_members].map { |v| self.trim_person }
        end
      )
    }
  end
end

# output of formatting the above, which is
# - not idempotent
# - what formatting the first bit should have produced in the first place
module Amp
  def self.trim_team(team)
    {
      descendent_members: (
        if team[descendant_members].present?
          team[:descendant_members].map { |v| self.trim_person }
        end
      )
    }
  end
end

Expected behavior

See embedded comments above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions