Skip to content

Second example of non idempotent formatting #150

Open

Description

@devonpmack

Original code

class Foo
  scope :by_bar, -> {
                              order(Arel.sql(
                                <<-SQL
                                  (CASE WHEN foo LIKE 'bar%' THEN 1 ELSE 2 END) asc,
                                  classification asc
                                SQL
                              ))
                            }
  scope :by_foo_and_bar, -> { by_classification.order(:foo) }
end

Format 1:

class Foo
  scope :by_bar, -> { order(Arel.sql(<<-SQL)) }
                                  (CASE WHEN foo LIKE 'bar%' THEN 1 ELSE 2 END) asc,
                                  classification asc
                                SQL
  scope :by_foo_and_bar, -> { by_classification.order(:foo) }
end

Format 2:

class Foo
  scope :by_bar, -> { order(Arel.sql(<<-SQL)) }
                                  (CASE WHEN foo LIKE 'bar%' THEN 1 ELSE 2 END) asc,
                                  classification asc
                                SQL

  scope :by_foo_and_bar, -> { by_classification.order(:foo) }
end

Activity

  1. davidtaylorhq commented on Jan 7, 2023

    @davidtaylorhq
    Contributor

    Here's a minimal reproduction of this issue:

    Original:

    string = (
      <<~RAW
        This is a heredoc
      RAW
    ).chomp
    a = b

    Format 1: (moves method call up)

    string = (<<~RAW).chomp
        This is a heredoc
      RAW
    a = b

    Format 2: (adds a newline after the heredoc)

    string = (<<~RAW).chomp
        This is a heredoc
      RAW
    
    a = b
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