mmoreram / php-formatter

PHP Formatter is a PHP developer friendly set of tools
MIT License
166 stars 17 forks source link

Sorting replaces \n by \r\n #19

Open jdomenechb opened 8 years ago

jdomenechb commented 8 years ago

When sorting use clauses in PHP files under a Windows system (I used Windows 7, with PHP 7 RC5), the sorting makes the file invalidate a PSR-2 rule, as the line endings appended are the default from Windows (\r\n), instead of the ones from UNIX (\n).

Please see the attached image to apreciate that the endings have only been replaced in use clauses.

sorting_r_n

mmoreram commented 8 years ago

Hi there!

Thanks for that feedback :) This project uses PHP_EOL for new lines. https://github.com/mmoreram/php-formatter/blob/master/src/PHPFormatter/Sorter/UseSorter.php#L249 Maybe here is the problem... :/

What do you think?

jdomenechb commented 8 years ago

Hi Marc,

As PSR is the standard, I will suggest to use what the rules say: "All PHP files MUST use the Unix LF (linefeed) line ending."

However, maybe it is interesting for some users to especify their custom new line string, or let them choose which they use from a defined list. For this, I would suggest adding another parameter to the application, and document it consequently, so users can have this flexibility :) If not specified, I would leave by default the Unix line ending (\n) as the PSR rules say.

Would this be something that could fit into the application?

mmoreram commented 7 years ago

@jdomenechb okay! Will do it :)