Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Bug #20272 phpcbf fails at fixing line endings
Submitted: 2014-05-11 05:10 UTC
From: phlopsi Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version SVN)
PHP Version: 5.5.12 OS: Windows 7
Roadmaps: (Not assigned)    
Subscription  


 [2014-05-11 05:10 UTC] phlopsi (Patrick Fischer)
Description: ------------ I used the newest version of the phpcs-fixer branch through composer. I ran the following command: C:\Users\Patrick\GitHub\access-control\src\phlopsi\access_control\exception>phpcbf.bat --standard=PSR2 -vvv RuntimeException.php > phpcbf.txt It exits with the message (found at the bottom of phpcbf.txt): Hunk #1 FAILED at 1 (different line endings). Test script: --------------- All relevant files: https://gist.github.com/phlopsi/b3435714b635cc73d436 Expected result: ---------------- fix line endings (\r\n -> \n) Actual result: -------------- no fix applied

Comments

 [2014-05-12 12:04 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz
When I generate a diff on the RuntimeException.php using Cygwin on Windows7, the patch file correctly includes the "\ No newline at end of file" line: $ php scripts/phpcs RuntimeException.php --report=diff --- RuntimeException.php +++ PHP_CodeSniffer @@ -1,7 +1,7 @@ -<?php - -namespace phlopsi\access_control\exception; - -class RuntimeException extends \RuntimeException implements Exception -{ -} \ No newline at end of file +<?php + +namespace phlopsi\access_control\exception; + +class RuntimeException extends \RuntimeException implements Exception +{ +} Given this is produced by the "diff" command and not PHPCS itself, I'm not sure where to fix it. Do you get the same issue if you run phpcs using --report=diff? You can also send use the --no-patch command line argument to get around this as it bypasses the diff and patch commands and replaces the file directly. More info is here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Fixing-Errors- Automatically#using-the-php-code-beautifier-and-fixer
 [2014-05-12 19:00 UTC] phlopsi (Patrick Fischer)
The problem was not the extra newline at the end, but the type of line ending. i had windows style (carriage return + newline feed) and PSR2 standard says, that all line endings should be linux style (newline feed). Anyway, it seems, when i uploaded the file to gist, it stripped the file of all carriage returns and automatically converted the line endings to linux style... So I up- and downloaded it again on my google drive and at least it doesn't change the file there. here is the link: https://drive.google.com/file/d/0B8QT8s3gLn0qSWF5N1RnY2xmYU0/edit?usp=sharing Just for your information, I added a comment to the file since last time, but it doesn't interfere with the problem.
 [2014-05-12 20:00 UTC] phlopsi (Patrick Fischer)
I just saw, that there was a scrollbar on your comment and tested the --no-patch thing and it seems to work. I googled for my problem and it turns out, that it's a problem with the diff command, converting the to-be-patched lines to linux style line endings. That's why the patch command doesn't work, as the line endings don't match. The posts I've seen are over a year old, so I guess it won't ever be "fixed". From now on, I will use --no-patch, but I guess it would be a good idea to mention in the documentation, that cygwin diff is not recommended and --no-patch should be used instead. Thanks.
 [2014-05-13 05:08 UTC] squiz (Greg Sherwood)
The weird thing is that cygwin diff works fine for me. I have diff version 3.2 and patch version 2.7.1. Different versions maybe? The other thing to try, which also works for me, is to create the diff file manually and test it: First, create the fixed copy of the file at RuntimeException.php.fixed php scripts/phpcbf RuntimeException.php --suffix=.fixed Then use cygwin diff to create the diff file manually, which is basically what happens inside PHPCBF anyway. diff RuntimeException.php RuntimeException.php.fixed > RuntimeException.diff Now patch the file using cygwin patch patch RuntimeException.php RuntimeException.diff When I do this, the errors about /r/n newlines are fixed. If
 [2014-05-13 05:09 UTC] squiz (Greg Sherwood)
Sorry, the comment was ended, despite the trailing "If" there.
 [2014-07-03 09:59 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: Closed
Please reopen if you are still having problems.