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

Error false positive when arrow function is used as a function argument #3853

Closed dan-usatoday closed 1 year ago

jrfnl commented 1 year ago

@dan-usatoday Could you please check what the default PHP version is on your machine (the one registered in your PATH) ? I suspect that is a PHP version below 7.4 (in which arrow functions didn't exist yet).

The Generic.PHP.Syntax sniff uses the PHP linter to find parse errors. If you want the sniff to use a different PHP version than the default version on your machine, you can tell PHPCS which PHP to use using --config-set php_path /path/to/php. Ref: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-path-to-php

Personally, I'd recommend using a dedicated linter, like PHP Parallel Lint, instead of using PHPCS for finding lint errors.