squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

PHPCS reports many errors that are not errors #3788

Closed tolki5 closed 1 year ago

tolki5 commented 1 year ago

I ran the phpcs function over the php file which works normally and got this error report.

`<?xml version="1.0" encoding="UTF-8"?>

` **This is my configuration file:** ` $phpCodeSnifferConfig = array ( 'default_standard' => 'PSR2', 'encoding' => 'windows-1250', 'show_warnings' => '0', 'php_version' => '50606', 'tab_width' => '4', 'severity' => '5', 'php_path' => 'C:\\PHP' )` I'm using this script: `C:\Users\Tolki\AppData\Roaming\Composer\vendor\bin\phpcs.bat --report=checkstyle D:\php\index.php` I would like to only return errors that are serious and prevent the script from running on the server. Such as a missing semicolon, parenthesis, etc. I don't care about errors like use spaces instead of tabs. I read the forums and apparently the problem is in the rullset. However, I am not able to get a rullset anywhere that would meet my requirements. I only want to point out errors that make it impossible to run the script on the server. Many thanks for support!
fredden commented 1 year ago

It sounds like you want the -l or --syntax-check flag for the php executable. https://www.php.net/manual/en/features.commandline.options.php

PHP_CodeSniffer is a tool for checking that code conforms to a particular coding standard.

tolki5 commented 1 year ago

Yes, this is exactly what i need. However, when calling php, in the event of an error, I get a response in this format:

Parse error: syntax error, unexpected '$resPcs' (T_VARIABLE) in D:\php\index.php on line 22 Errors parsing D:\php\index.php

This format is not compatible with https://github.com/deadem/notepad-pp-linter, which I would like to use in notepad++ to pre-check scripts.

Only supported format is from phpcs: <?xml version="1.0" encoding="UTF-8"?> <checkstyle version="2.9.2"> <file name="D:\php\index.php"> <error line="1" column="1" severity="error" message="End of line character is invalid; expected &quot;\n&quot; but found &quot;\r\n&quot;" source="Generic.Files.LineEndings.InvalidEOLChar"/></file></checkstyle>

jrfnl commented 1 year ago

@tolki5 Sounds like you are looking for a tool like PHP Parallel Lint.

Note: this repo is not a general PHP tooling support forum. You may be better off in StackOverflow or something.

gsherwood commented 1 year ago

Agree with @jrfnl - sounds like you're not looking for a tool to enforce coding standards. Try the linter and you'll get what you need.