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 doesn't see obvious syntax errors #3740

Closed dvhx closed 1 year ago

dvhx commented 1 year ago
<?php
/**
Phpcs thinks this file is ok
php version 8.1.2

@category Asdf
@package  Asdf
@author   Me <me@example.com>
@license  GNU GPL v3 http://example.com/
@link     http://example.com/
 */
$x => 123;
jrfnl commented 1 year ago

Duplicate of #3693, #3491, #2930

PHPCS is often used within IDEs during live coding, so, generally speaking, it will ignore parse errors. Along the same lines, something which may be a parse error in one PHP version, may not be on another PHP version.

If you want parse errors to be reported, you can add the Generic.PHP.Syntax sniff to your ruleset, though be aware that it will report based on the PHP version used during the PHPCS scan. Alternatively, use a dedicated linting tool like PHP Parallel Lint or PHPLint.