| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | 0.8.x-dev@40275b2 |
| Installed as | demo site |
Rector is showing a removal of the end curly brace, and then the addition of the same curly brace for the last curly brace in the file. Near as I can tell, the new one is identical to the old one in position.
https://getrector.org/demo/5c6d0d01-0a96-4be6-bc7f-0e4b0c184d7e#result
It doesn't matter what set you pass here, I believe.
Do nothing.
It's seems like newline ending. Print-file adds newline by default, as is common practise.
@TomasVotruba, I'm sorry, I don't understand what you mean by print-file?
Is it possible to do something about this, either on my end or yours? If I run rector against a bundle in my project it reports it's changed 65 files, but none of the files have actually changed, it's all of this ending new line thing.
I take the output as JSON and feed the diffs into BeyondCompare to see what's changing, but it's overwhelming BeyondCompare with files that haven't actually changed.
This might be the cause: https://github.com/rectorphp/rector/commit/192c4464ec5bf85028ca54c65f25f3fb2bbbd293#diff-560bcf8e3b306989b3cb6718d0403d0c
It was fix of some other problem (not sure which). If you find a way to make your code work + tests pass here, send pull-request. I'd be happy to merge it
Thanks. That looks promising.
If I had to take a guess right now, I'm going to guess it's because I develop on Windows, for Linux. So the line endings in the file are Linux endings. But I run rector locally, so the PHP_EOL is the windows line ending.
I will spend some time looking into this in the next day or two, but if I'm right, what about detecting the line ending for the file and using that instead of PHP_EOL?
Weird, I just run into same situation. Had to do some debugging to get to the problem. Can't we define the line separator just like it's done within ecs?
parameters:
line_ending: '\n'
I'd be open to such feature :+1:
From what I see, the Rector BetterStandardPrinter extends PHP Parser's Standard Printer, and that class assumes Unix style n as a line separator, anyway. So using PHP_EOL in Rector's Printer will be a different end of line than the rest of the file if Rector is run from Windows or a very old Mac. Here's an issue from PHP Parser about newline from a year ago:
https://github.com/nikic/PHP-Parser/issues/599
Changing PHP_EOL to $this->nl in BetterStandardPrinter seems to "fix" the issue, for me, by just using n, like the rest of the Standard Printer. It may not be right, but at least it's consistent?
I'm not sure exactly what changes were done since PR #3390, but with latest version I'm getting a different end of line again.

This might have caused it: https://github.com/rectorphp/rector/commit/6c0bc2d14b36fa3b1c2e7503ec68c5ae5b0f8503#diff-560bcf8e3b306989b3cb6718d0403d0c
It was to prevent adding the newline in existing files.
Maybe the regex is not quite right. I'm not sure how to fix it to keep original code untouched and new code with propper newline.
Actually seems I didn't have latest version, I had v0.7.26. Can't update to v0.7.27 because I also have symplify/easy-coding-standard:
Problem 1
- Can only install one of: phpstan/phpdoc-parser[0.4.7, 0.4.4].
- Can only install one of: phpstan/phpdoc-parser[0.4.7, 0.4.4].
- Can only install one of: phpstan/phpdoc-parser[0.4.7, 0.4.4].
- rector/rector v0.7.27 requires phpstan/phpdoc-parser ^0.4.7 -> satisfiable by phpstan/phpdoc-parser[0.4.7].
- Installation request for rector/rector ^0.7.27 -> satisfiable by rector/rector[v0.7.27].
- Installation request for phpstan/phpdoc-parser (locked at 0.4.4) -> satisfiable by phpstan/phpdoc-parser[0.4.4].
But it's fine, I tested with rector/rector-prefixed v0.7.27 and no more problems with the end of line.
Most helpful comment
From what I see, the Rector BetterStandardPrinter extends PHP Parser's Standard Printer, and that class assumes Unix style n as a line separator, anyway. So using PHP_EOL in Rector's Printer will be a different end of line than the rest of the file if Rector is run from Windows or a very old Mac. Here's an issue from PHP Parser about newline from a year ago:
https://github.com/nikic/PHP-Parser/issues/599
Changing
PHP_EOLto$this->nlin BetterStandardPrinter seems to "fix" the issue, for me, by just using n, like the rest of the Standard Printer. It may not be right, but at least it's consistent?