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: ERROR: Referenced sniff "SlevomatCodingStandard.Arrays.TrailingArrayComma" does not exist #2942

Closed progredi closed 3 years ago

progredi commented 4 years ago

Started receiving this error message in PhpStorm 2020.1 yesterday, after installing PHPStan. Pops up after every file save.

gsherwood commented 4 years ago

Is this an error you can reproduce from the command line?

I ask because I don't maintain a PHPStorm plugin, or the Slevomat coding standard, or PHPStan, so I don't know how to even begin replicating this issue.

devcorrelator commented 4 years ago

I recently did a composer update and now I'm getting this error:

ERROR: Referenced sniff "SlevomatCodingStandard.Arrays.TrailingArrayComma" does not exist

Versions: phpstan/phpstan: 0.12.29 squizlabs/php_codesniffer: 3.5.5 cakephp/cakephp-codesniffer: 4.2.0 slevomat/coding-standard: 6.3.9

jrfnl commented 4 years ago

@devcorrelator While similar, your issue is not necessarily the same as the one discussed here.

You needs to make sure that the CakePHP and the Slevomat standards are registered with PHPCS via the installed_paths.

Run vendor/bin/phpcs -i to see which standards are installed. If either of them are missing, that's your problem. This is how you set the installed_paths: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-installed-standard-paths

Alternatively, as you're using Composer anyway, you can use the following Composer plugin to register the installed_paths automatically for you: https://packagist.org/packages/dealerdirect/phpcodesniffer-composer-installer

devcorrelator commented 4 years ago

@jrfnl Thank you so much! it set me on the path to fix it. I tried that package, but it was throwing an issue where that class can't be autoladed. I ended up following the directions in the link that you sent me, and updated my phpcs.xml file.

For future reference to anyone googling in the future: I'm running php in composer link so:

"scripts": {
        "fix": [
            "@cs-fix",
            "@cs-check"
        ],
        "cs-check": "vendor/bin/phpcs --colors -p -s --extensions=ctp,php ./src ./tests ./config",
        "cs-fix": "vendor/bin/phpcbf --colors --extensions=ctp,php ./src ./tests ./config"
    }

and composer fix

Here is my phpcs.xml. This is where I had to list the other standards:

<?xml version="1.0"?>
<ruleset name="App">
    <description>App Coding Standard</description>
    <config name="installed_paths" value="../../cakephp/cakephp-codesniffer"/>
    <config name="installed_paths" value="../../slevomat/coding-standard"/>

    <!-- Allow TODO tags -->
    <rule ref="Generic.Commenting.Todo.CommentFound">
        <severity>0</severity>
    </rule>
    <rule ref="Generic.Commenting.Todo.TaskFound">
        <severity>0</severity>
    </rule>
</ruleset>
motooka commented 5 months ago

FYI, on my environment (PhpStorm, docker-compose on Mac and CakePHP ), I have also suffered from the pop-ups described in this thread. The Reset PHP_CodeSniffer configuration guide in PhpStorm help page did the trick for me. https://www.jetbrains.com/help/phpstorm/using-php-code-sniffer.html#reset-tool-configuration

earthiverse commented 4 months ago

I had this error in one of the projects I was working on. It used an older version of Composer (1.1) in its Dockerfile. Upgrading Composer (I went to 2.7) fixed the issue.