Search code examples
phpcodesnifferphpcs

PHP CodeSniffer: ERROR: The specified sniff code "Generic.Files.LineEndings.InvalidEOLChar" is invalid


My attempt to exclude the check for the EOL char on my Windows machine always results in this error message:

>vendor\bin\phpcs.bat --standard=PSR2 --exclude=Generic.Files.LineEndings.InvalidEOLChar src\version.php
ERROR: The specified sniff code "Generic.Files.LineEndings.InvalidEOLChar" is invalid

Run "phpcs --help" for usage information

Can't figure out what I'm doing wrong. I have installed PHP CodeSniffer via composer and am running version 3.4.0.


Solution

  • The --exclude CLI argument accepts 3-part sniffs codes, but you've passed in a 4-part error code.

    In your case, the sniff code is Generic.Files.LineEndings and that sniff only generates a single error code, so you'll be fine ignoring the entire sniff:

    vendor\bin\phpcs.bat --standard=PSR2 --exclude=Generic.Files.LineEndings src\version.php
    

    If you want to exclude individual error codes, or if you just want to lock down a standard for your project, you'll need to use a ruleset.xml file: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset