On 8.3.14 (but not 8.3.13): ERROR: Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist

Created on 3 February 2022, over 3 years ago
Updated 26 January 2023, over 2 years ago

Problem/Motivation

When using version 8.3.14 from January 28, I get "ERROR: Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist":

When using version 8.3.13, it works as expected.

Steps to reproduce

composer global require \
  drupal/coder

phpcs --standard=Drupal example.module 
ERROR: Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist
composer global require \
  drupal/coder:8.3.13

phpcs --standard=Drupal example.module 
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
  1 | ERROR | [x] Missing file doc comment
 14 | ERROR | [x] Expected 1 space after FUNCTION keyword; newline
    |       |     found
 17 | ERROR | [x] Multi-line function declarations must define one
    |       |     parameter per line
----------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

I am running this within a Docker container [using this project](https://github.com/dcycle/docker-php-lint).

Proposed resolution

Coder 8.3.14 now depends on the SlevomatCodingStandard and will setup the phpcs installed_paths configuration automatically on composer install with the dealerdirect/phpcodesniffer-composer-installer plugin. During the composer install process you need to answer Do you trust "dealerdirect/phpcodesniffer-composer-installer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] with "y" (yes, we trust this plugin to setup PHPCS paths).

Please also remove all extra commands that set the installed_paths with phpcs from any Coder setup scripts you use.

If you have a composer vendor directory already then you might have an outdated vendor/squizlabs/php_codesniffer/CodeSniffer.conf file there. Reinitialize that:

rm -rf vendor/squizlabs/php_codesniffer/
composer install

Again make sure that you trust the "dealerdirect/phpcodesniffer-composer-installer" plugin. Your composer.json file should look similar to this:

{
    "require": {
        "drupal/coder": "^8.3"
    },
    "config": {
        "allow-plugins": {
            "dealerdirect/phpcodesniffer-composer-installer": true
        }
    }
}

The composer install should print PHP CodeSniffer Config installed_paths set to ../../drupal/coder/coder_sniffer,../../sirbrillig/phpcs-variable-analysis,../../slevomat/coding-standard, then you know the new Slevomat coding standard path was configured.

Remaining tasks

Fix Drupal.org testbot script which has a hard-coded --config-set installed_paths command.
#3283978: Remove --config-set installed_paths (Referenced sniff does not exist)

🐛 Bug report
Status

Active

Version

8.3

Component

Coder Sniffer

Created by

🇨🇦Canada alberto56

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇩Bangladesh eashika

    hello @mandclu, #34 could you please elaborate on the steps, please? I installed phpcs with homebrew as well and facing the same issue

  • 🇮🇳India AnokR

    Hello @all, I was having same error when downgrading the coder version to "8.3.13" run the command composer require drupal/coder:8.3.13 fix my issue.

  • #36 💬 On 8.3.14 (but not 8.3.13): ERROR: Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist Active works for me.

    Also after downgrading Coder to the 8.3.13 version you can upgrade it again to the latest one and Slevomat coding standards appear in phpcs -i. At least it did a "trick" for me.

  • 🇺🇸United States AaronBauman Philadelphia

    after R'ing TFA, I realized I needed to make a couple updates to my project's composer.json to get this working on latest coder stable.

    Remove any config-set step from composer.json:
    bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer

    Then remove dependencies which are now integrated with this module:

    composer remove squizlabs/php_codesniffer dealerdirect/phpcodesniffer-composer-installer
    composer update drupal/coder -W

    Good to go after that.

  • Thank you, @geoanders. I downgraded coder (composer global require drupal/coder:8.3.13) and it fixed the issue right away.

    #18 worked for me thank you @geoanders

  • same issue for me on latest but not on 8.3.16

  • 🇹🇭Thailand Nick Hope

    The downgrade-then-upgrade trick in #37 worked for me.

    Downgrade to 8.3.13:
    composer global require drupal/coder:8.3.13
    Upgrade to the latest version (currently 8.3.13):
    composer global require drupal/coder
    Verify installed coding standards:
    phpcs -i outputs (for me):
    The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, Drupal, DrupalPractice, VariableAnalysis and SlevomatCodingStandard

  • 🇬🇧United Kingdom jonnyhocks

    Just to expand on #33 💬 On 8.3.14 (but not 8.3.13): ERROR: Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist Active , I was also experiencing the issue with PHPStorm even though the issue had been resolved when running with CLI.

    I removed the installed paths section from the .idea/php.xml file. I'm guessing that some config is saved in different places depending on which version of PHPStorm you are using.

  • 🇦🇺Australia dynamdilshan

    #18 worked for me as I followed the instructions from this resource below:
    https://gorannikolovski.com/blog/referenced-sniff-slevomat-coding-standa...

    I'm on D9.5, PHP 8.1 and the latest version of coder module.

  • 🇺🇸United States selwynpolit

    Just to elaborate on #42. I found that by editing the .idea/php.xml file, even while PHPStorm is open, and removing the line:

        <option name="installedPaths" value="$PROJECT_DIR$/vendor/drupal/coder/coder_sniffer" />
    

    from the section displayed below, the error immediately went away.

      <component name="PHPCodeSnifferOptionsConfiguration">
        <option name="codingStandard" value="Drupal" />
        <option name="highlightLevel" value="WARNING" />
        <option name="installedPaths" value="$PROJECT_DIR$/vendor/drupal/coder/coder_sniffer" />
        <option name="useInstalledPaths" value="true" />
        <option name="transferred" value="true" />
      </component>
    
  • 🇷🇺Russia Dimetry

    #44 does work. Many thanks.

  • 🇮🇳India Sivaji_Ganesh_Jojodae Chennai

    #36 works. Downgrading drupal/coder (8.3.21 => 8.3.13).

  • 🇧🇬Bulgaria pfrenssen Sofia

    Changing this to a support request since this is not a bug in coder but rather a configuration issue on the user side.

  • 🇫🇷France fgm Paris, France

    Seeing how it's so common since it happens as the default in the most popular IDE, I would say it's rather a bug, but that's your call.

  • 🇺🇸United States TomTech

    I just encountered this issue.

    You shouldn't need to edit any PhpStorm XML files. There is a setting for this.

    Seems that JetBrains was being helpful, as this is configuration specifically documented for this module(and similar implementations): PHP - Quality Tools - PHP Code Sniffer.

    You can clear the field and uncheck the "Installed standards path" to remove this setting in PhpStorm.

    Seems some communication should be made with JetBrains that the latest version of coder requires multiple paths, not a single path. (Or could we just symlink the other directories into the coder directory as an alternative?)

  • 🇺🇸United States emb03

    #36 worked for me

  • 🇺🇸United States j. ayen green

    @TomTech #49 (using ddev and PhPStorm) ... I owe you a beer!

  • 🇺🇸United States selwynpolit

    Hopefully I captured the steps correctly here to save others some time: https://selwynpolit.github.io/d9book/setup_mac#code-sniffing

  • 🇬🇧United Kingdom alexharries

    Hmm, I'm not having any luck fixing this issue on the command line or in PHPStorm despite following the steps in #44 and Selwynpolit's guide (thank you for the guide! Very helpful).

    Following in hope of a resolution :)

    Alex

  • 🇺🇸United States selwynpolit

    @alexharries, did you try installing Drupal dev tools in your project with `composer require drupal/core-dev` ?

  • 🇺🇸United States selwynpolit

    I learned some new thing about how to make this work with PHPStorm. Details at https://selwynpolit.github.io/d9book/setup_mac#code-sniffing

  • 🇦🇺Australia skyejohnson Sunshine Coast, Australia

    Many thanks for the guide @selwynpolit, it fixed this issue for me in PHPStorm just now.

  • 🇬🇧United Kingdom hocu London

    DDEV and PhpStorm users just follow the instructions in @TomTech's comment (#49) and you're good to go.

  • 🇵🇱Poland piotr pakulski Poland 🇪🇺

    I experience the "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist still in inteliJ with correctly set setup. And so:

    • file vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/RequireNullCoalesceOperatorSniff.php exists
    • PHP_CodeSniffer version 3.11.1
    "require-dev": {
                    "chi-teck/drupal-coder-extension": "^2.0.0-alpha4",
                    "drupal/coder": "8.3.22",
                    "drupal/core": "10.1.x-dev",
                    "ext-simplexml": "*",
                    "phpspec/prophecy-phpunit": "^2.0",
                    "phpunit/phpunit": "^9.5",
                    "squizlabs/php_codesniffer": "^3.7",
                    "symfony/var-dumper": "^6.3",
                    "symfony/yaml": "^6.3",
                    "vimeo/psalm": "^5.14.0"
                },
  • 🇵🇱Poland piotr pakulski Poland 🇪🇺

    and for drupal/coder 8.3.28 I'm getting "SlevomatCodingStandard.Classes.BackedEnumTypeSpacing" does not exits

  • 🇧🇪Belgium LRoels Ghent

    I am getting the same error as #59 even when using phpcs through the command line.
    I guess something is wrong in the v8.3.28 install as well since I don't have the issue on a previous version (8.3.13).

  • 🇦🇺Australia interlated

    > composer global require slevomat/coding-standard

    Enabled the "Drupal" coding standard to appear in the Intellij configuration. Drupal 11.

    > composer global require drupal/coder
    > composer global require slevomat/coding-standard

    I don't know why the second dependency is not picked up.

    phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer,~/.composer/vendor/sirbrillig/phpcs-variable-analysis,~/.composer/vendor/slevomat/coding-standard

    Set ruleset files php,module,inc,install,test,profile,theme,css,info,txt,md,yml

    phpcs -i
    The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, Drupal and DrupalPractice

    Test

    phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml --sniffs=Drupal.Classes.UnusedUseStatement web/modules/custom/a_module

    Appeared in the configuration under PHP - Quality Tools - PHP Code Sniffer.

Production build 0.71.5 2024