Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 924
Tobias Uhmann Avatar asked Mar 11 '19 09:03

Tobias Uhmann


People also ask

How do I report a PHP_codesniffer error?

If PHP_CodeSniffer finds any coding standard errors, a report will be shown after running the command. Full usage information and example reports are available on the usage page. The documentation for PHP_CodeSniffer is available on the Github wiki. Bug reports and feature requests can be submitted on the Github Issue Tracker.

What is @PHP_codesniffer?

PHP_CodeSniffer allows developers to design their own coding standards by creating a simple ruleset XML file that both pulls in sniffs from existing standards and customises them for the developer's needs. This XML file can be named anything you like, as long as it has an xml extension and complies to the ruleset.xml format.

How do I install PHP_codesniffer on phive?

If you use Phive, you can install PHP_CodeSniffer as a project tool using the following commands: You will then be able to run PHP_CodeSniffer from the tools directory: PEAR. If you use PEAR, you can install PHP_CodeSniffer using the PEAR installer.

How do I run PHP_codesniffer from a Git clone?

You can also download the PHP_CodeSniffer source and run the phpcs and phpcbf commands directly from the Git clone: The default coding standard used by PHP_CodeSniffer is the PEAR coding standard. To check a file against the PEAR coding standard, simply specify the file's location:


1 Answers

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

like image 106
Greg Sherwood Avatar answered Oct 07 '22 14:10

Greg Sherwood