8

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.

Tobias Uhmann
  • 2,757
  • 2
  • 25
  • 35

1 Answers1

11

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

Greg Sherwood
  • 6,992
  • 2
  • 29
  • 24
  • 1
    Assuming a user doesn't just magically know the name of the sniff code, how does someone find a specific sniff code from a shown error/warning, in order to know which one to exclude? – mbomb007 Dec 23 '19 at 20:13
  • 3
    Run PHPCS with the `-s` command line argument. The error message code will be displayed after each error message, and is in the format `Standard.Category.Sniff.Error`. If you want to exclude or change that single error message, use that 4-part code. If you want to exclude the while sniff, use the first 3 parts only. – Greg Sherwood Dec 25 '19 at 23:59
  • 2
    @GregSherwood IMHO it's a shame that this rule (`--exclude` accepts 3-parts sniff codes) isn't documented explicitly anywhere... Shouldn't this be added here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#limiting-results-to-specific-sniffs ? – Yannoff Oct 27 '20 at 10:10