dlang-community / dfmt

Dfmt is a formatter for D source code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`end_of_line` defaults to LF, even on Windows.

veelo opened this issue · comments

dfmt produces non-native line endings on Windows, unless explicitly instructed with --end_of_line=crlf. This is unfortunate, as explicitly stating --end_of_line in scripts makes it difficult to maintain cross platform compatibility.

Most editors on Windows will produce CRLF line endings by default, and even Git will by default convert files to CRLF on checkout. Most text files will therefore have CRLF endings on Windows, and users may be surprised to find their files having LF endings after a run through dfmt.

There was a long discussion by the folks of editorconfig about whether --end_of_line should support a native setting, and whether that should be the default. It was decided that this was not a good idea, and that unset is the desired default, meaning to leave the default up to the editor.

But, since dfmt often introduces line breaks, it needs some kind of default. And LF is not the right default in every case, IMO.

The obvious solution would be to make CRLF the default on Windows, and LF everywhere else. However, as reported in the above linked thread, some people configure Git to check out all files using LF also on Windows, and they would not want dfmt to change line endings away from their preference.

The most versatile solution would probably be to inspect the first n lines of input and see what the dominating line endings are there, and use that as default for the entire output.