prettier-ruby icon indicating copy to clipboard operation
prettier-ruby copied to clipboard

String/Symbol arrays not correctly formatted when indentation present

Open AlanFoster opened this issue 7 years ago • 2 comments

Raising this is as a separate issue to keep track of it:

https://github.com/iamsolankiamit/prettier-ruby/pull/4#discussion_r192064062

Input

def symbols
  %i(
    a
    b
    c
    d
  )
end

symbols

Current output

def symbols
  ['    a', '    b', '    c', '    d']
end

symbols

Expected Output

  • Output should equal input still
  • Or, formated with array syntax with without the extra whitespace

AlanFoster avatar May 31 '18 12:05 AlanFoster

Some concrete expected outputs:

Strings

Either convert to array and ensure whitespace isn't present:

def strings
  ['a', 'b', 'c', 'd']
end

strings

Or output the same %w( ... ) syntax:

def strings
  %w( a b c d )
end

strings

Symbols

Potential symbols output:

def symbols
  [:a, :b, :c, :d]
end

symbols

Or:

def symbols
  %i( a b c d )
end

symbols

Note:: that prettier-ruby is actually converting symbols to strings incorrectly with the current implementation too, which I didn't notice originally

AlanFoster avatar May 31 '18 12:05 AlanFoster

right now if it is a symbol or string array we print it properly. we can consider converting [:a, :b] into %i[a b].

iamsolankiamit avatar Jul 21 '18 10:07 iamsolankiamit