xml-formatter icon indicating copy to clipboard operation
xml-formatter copied to clipboard

Please make the default `lineSeparator` just '\n'

Open rrthomas opened this issue 3 years ago • 2 comments

The current default is surprising, and causes problems when mixed with output from other programs which just use the standard line separator.

On a system that uses CRLF as its line separator, the caller of xml-formatter should just output the formatted XML as text, not binary, and the system will automatically translate \n to CRLF; there should be no need for a custom lineSeparator for this use case.

Thanks for xml-formatter!

rrthomas avatar Aug 25 '21 12:08 rrthomas

I'm afraid we might upset some people if we do that.

But there could be a compromise by using https://nodejs.org/api/os.html#os_os_eol to detect what should be used if the lineSeparator option is missing but that would be a breaking change.

Why do you set the lineSeparator option to \n in your code?

chrisbottin avatar Aug 26 '21 19:08 chrisbottin

I can believe that changing this default would cause some users problems, but it would be interesting to know in what circumstances.

Defaulting to the OS's EOL would be better, but it's still odd: why would you want an EOL rather than a newline other than when writing to a text stream?

I needed to set lineSeparator because I am outputting the result of format() to a text file on a system whose line ending is LF. Having the wrong line endings would be a problem in itself; in my case it was slightly worse because only part of the file's contents was the output of format().

rrthomas avatar Aug 26 '21 19:08 rrthomas

Thanks for considering this!

rrthomas avatar Dec 15 '22 21:12 rrthomas