Referenced sniff "Slevomat Coding Standard" does not exist

Depending on your project setup, updating the Coder module (it's actually not a module but a library) from earlier versions to version 8.3.14 might lead to the referenced sniff does not exist error:

ERROR: Referenced sniff "SlevomatCodingStandard ControlStructures RequireNullCoalesceOperator" does not exist

The quick fix is to pin Coder to version 8.3.13 in your composer.json file and execute the following command to downgrade the module:

composer update --with-dependencies drupal/coder

But don't do that. That's not the right way to solve the issue. What you should do instead is to check the command that you use to run the Drupal code check. If you see something like this: --config-set installed_paths then just remove that command.

Also, if you are using the phpcs.xml file to configure PHPCS for your project then search for something like this config name="installed_paths" and remove it.

Setting the installed standard paths for Drupal code sniffer manually is no longer required. That's because Coder 8.3.14 now depends on the PHPCSStandards/composer-installer package which provides a Composer plugin that allows for easy installation of PHP_CodeSniffer coding standards. The installed_paths will be automatically set when you install the Coder module.

So, starting from version 8.3.14 you don't have to worry about checking out coding standard repositories in specific locations, changing the PHP_CodeSniffer configuration, or symbolic linking of directories. Just run the command to check the coding standards.

Here are the before and after examples:

Before (Coder 8.3.13 and earlier)

bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer && 
bin/phpcs -p --colors --standard=Drupal,DrupalPractice --extensions=php,module,install web/modules/custom/

After (Coder 8.3.14 and later):

bin/phpcs -p --colors --standard=Drupal,DrupalPractice --extensions=php,module,install web/modules/custom/

If even after removing the command you still see the error make sure that you have all Coder dependencies installed properly. If some of them are missing just run the following Composer command:

composer update --with-dependencies drupal/coder

By the way, the Slevomat Coding Standard for PHP_CodeSniffer has some very useful sniffs, so Coder started using it from version 8.3.14. To find out more about that check the following issue.

About the Author

Goran Nikolovski is a web and AI developer with over 10 years of expertise in PHP, Drupal, Python, JavaScript, React, and React Native. He founded this website and enjoys sharing his knowledge.