styler icon indicating copy to clipboard operation
styler copied to clipboard

Alignment in `switch()` statements is not preserved when elements are missing

Open IndrajeetPatil opened this issue 3 years ago • 1 comments

When no elements missing: alignment preserved

styler::style_text(text = "
  switch(
    word,
    a   = 1,
    ab  = 2,
    abc = 3
  )")
#> 
#> switch(word,
#>   a   = 1,
#>   ab  = 2,
#>   abc = 3
#> )

When elements missing: alignment not preserved

styler::style_text(text = "
  switch(
    word,
    a   = 1,
    ab  = ,
    abc = 3
  )")
#> 
#> switch(word,
#>   a = 1,
#>   ab = ,
#>   abc = 3
#> )

Created on 2022-10-05 with reprex v2.0.2

Expected

#> switch(word,
#>   a   = 1,
#>   ab  =  ,
#>   abc = 3
#> )

IndrajeetPatil avatar Oct 05 '22 19:10 IndrajeetPatil

I am not sure I consider

switch(
    word,
    a   = 1,
    ab  = ,
    abc = 3
  )

Aligned. I think it had to be

switch(
    word,
    a   = 1,
    ab  =  ,
    abc = 3
  )

But even then, it does not give the expected result.

lorenzwalthert avatar Oct 17 '22 06:10 lorenzwalthert