Skip to content

Second example of non idempotent formatting #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
devonpmack opened this issue Aug 25, 2022 · 1 comment
Open

Second example of non idempotent formatting #150

devonpmack opened this issue Aug 25, 2022 · 1 comment

Comments

@devonpmack
Copy link

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
@davidtaylorhq
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants