Skip to content

phpcs on windows throws on every file following error: End of line character is invalid; expected "\n" but found "\r\n"  #32

@rakoitde

Description

@rakoitde

Actual behavior

phpcs on windows throws on every file following error: End of line character is invalid; expected "\n" but found "\r\n"

FILE: ...\MAMP\htdocs\api-client-php\tests\Idoit\APIClient\SubnetTest.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 1 | ERROR | [x] End of line character is invalid; expected "\n" but
   |       |     found "\r\n"
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Found this Issue:
squizlabs/PHP_CodeSniffer#2554

Steps to resolve the behavior

I'm not firm with phpcs, so I can't judge if my successful test can be a solution!

  1. create ruleset.xlm from following link
    https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/src/Standards/PSR2/ruleset.xml

  2. Change eolChar from "\n" to "\r\n"

    <rule ref="Generic.Files.LineEndings">
        <properties>
            <property name="eolChar" value="\r\n"/>
        </properties>
    </rule>
  1. comment excludes
<!-- checked by PSR2.Classes.ClassDeclaration -->
<!-- <rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/> -->
  1. add script in composer.json

"phpcs-win": "./vendor/bin/phpcs --standard=ruleset.xml --extensions=php src/ tests/",

  1. Test works fine

composer phpcs-win

Environment

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions