rufo icon indicating copy to clipboard operation
rufo copied to clipboard

rufo aligns HEREDOCs funny

Open SamSaffron opened this issue 7 years ago • 5 comments

def a
  test = DB.exec <<~SQL
    UPDATE table set col = 1
  SQL
end

Is aligned:

def a
  test = DB.exec <<~SQL
                   UPDATE table set col = 1
                 SQL
end

Which is somewhat odd... it aligns as expected for DB.exec(<<~SQL)

Note, now the we adopted Prettier for Discourse js I am very very keen to move to rufo, from my tests on a few files this appears to be the biggest point of contention, there is some around params as well cause our rubocop rules currently are at odds with what rufo produces.

SamSaffron avatar Jul 17 '18 08:07 SamSaffron

I have another example of unexpected heredoc formatting that I think is definitely not desired behavior:

        expect(   
          course_type.resolve(<<~GQL, current_user: @student)
            assignmentsConnection(filter: {gradingPeriodId: null}) { edges { node { _id } } }
          GQL
        ).to match course.assignments.published.map(&:to_param)

becomes

        expect(
          course_type.resolve(<<~GQL, current_user: @student)
            assignmentsConnection(filter: {gradingPeriodId: null}) { edges { node { _id } } }
          GQL
········
).to match course.assignments.published.map(&:to_param)

(the ········ in this case is whitespace that rufo is introducing for whatever reason).

cmatheson avatar Aug 22 '18 21:08 cmatheson

Rufo will format HEREDOCs invalidly too, e.g.

Turn this valid, and in my opinion, correctly formatted HEREDOC

    execute (<<-SQL).gsub(/\n\s+/, " ")
       # Some complex SQL migration thats being dedented
    SQL

Into

    execute (<<-SQL
).gsub(/\n\s+/, " ")
       # Some complex SQL migration thats being dedented
    SQL

After it's done this it will then be unable to parse the file again, as it's now not valid Ruby.

JonRowe avatar Nov 02 '18 10:11 JonRowe

Rufo somehow added very long lines of spaces for some my heredoc strings (and has completely broken tilda heredocs contents with that).

alsemyonov avatar Nov 12 '18 15:11 alsemyonov

FWIW I noticed that it will keep adding more indentation each time rufo is run. In other words it doesn't get to a stable formatting. This is with the latest version of rufo at the time of writing this (0.7.0).

braindev avatar Aug 13 '19 21:08 braindev

I created a new issue #188 specifically for the rowing whitespace issue

lastobelus avatar Nov 01 '19 17:11 lastobelus