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

1

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.

Halinahalite answered 11/3, 2019 at 9:31 Comment(0)
P
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

Prue answered 11/3, 2019 at 22:15 Comment(3)
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?Phrixus
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.Prue
@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: github.com/squizlabs/PHP_CodeSniffer/wiki/… ?Axinomancy

© 2022 - 2024 — McMap. All rights reserved.