nixfmt icon indicating copy to clipboard operation
nixfmt copied to clipboard

nixfmt incorrectly transforms strings to double single quote form

Open florpe opened this issue 2 years ago • 2 comments

Description

Nixfmt (sometimes?) converts strings to double single quote form. For certain strings, the transformation is incorrect. No transformation at all would be preferrable.

Small example input

  someValue = ",\n    ";

Expected output

  someValue = ",\n    "; # Unchanged, no transformation necessary

Actual output

  someValue = ''
    ,
        ''; # Equivalent to "\n,"

florpe avatar Apr 10 '22 23:04 florpe

The conversion to multiline strings is something that's been very ergonomic for my team, so we'd be sad to lose it. A length heuristic might help?

That said, here's another incorrect transformation.

Sample input

"\n'"

Expected output

''

''\'''

Actual output

''

  '''

The output doesn't parse anymore.

parenthetical avatar Jul 07 '22 12:07 parenthetical

Edit: it seems like this one is fixed in 0.5.0!

Another case:

Sample input

"'\${x:y}'\n"

Expected output

''
  ''\'''${x:y}'
''

Actual output

''
  '''${x:y}'
''

parenthetical avatar Jul 08 '22 14:07 parenthetical

Yep! Fixed in v0.5.0!

yorickvP avatar Oct 21 '22 07:10 yorickvP