3

Just installed php_codesniffer and coder:

composer global require "squizlabs/php_codesniffer=*"
composer global require drupal/coder

After installation, run phpcs -i and the result is as follows:

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

But when I use git commit, I get an error:

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

My php version is 7.4. Where am I going wrong?

River Zhao
  • 73
  • 2
  • 8

3 Answers3

2

Excuting an order:

 phpcs --config-set installed_paths /homeriverz/.config/composer/vendor/phpcompatibility/php-compatibility,/homeriverz/.config/composer/vendor/drupal/coder/coder_sniffer,/homeriverz/.config/composer/vendor/slevomat /coding-standard

If not, reinstall php_codesniffer and drupal/coder.

ouflak
  • 2,458
  • 10
  • 44
  • 49
River Zhao
  • 73
  • 2
  • 8
0

One trick is to downgrade drupal/coder to 8.3.13, then upgrade it to the latest version. This worked for me, with current version 8.3.18.

Downgrade to 8.3.13:

composer global require drupal/coder:8.3.13

Then upgrade to the latest version:

composer global require drupal/coder

Then verify installed coding standards:

phpcs -i

For me, that outputs:

"The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, Drupal, DrupalPractice, VariableAnalysis and SlevomatCodingStandard"

More info and options at https://www.drupal.org/project/coder/issues/3262291

Nick Hope
  • 139
  • 1
  • 9
0

I had a similar issue. was using this document to install php code sniffer for drupal. Installing Coder Sniffer

did the following step

phpcs --config-set installed_paths /home/dld/vendor/drupal/coder/coder_sniffer

Using config file: /home/dld/vendor/squizlabs/php_codesniffer/CodeSniffer.conf Config value "installed_paths" updated successfully; old value was "../../drupal/coder/coder_sniffer,../../sirbrillig/phpcs-variable-analysis,../../slevomat/coding-standard"

and then tried running it on drupal module file

it gave the following message

drupalcs hello_world.module

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

Hence i did the following to fix it.

phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer,../../sirbrillig/phpcs-variable-analysis,../../slevomat/coding-standard,/home/dld/vendor/drupal/coder/coder_snifferUsing config file: /home/dld/vendor/squizlabs/php_codesniffer/CodeSniffer.conf

Config value "installed_paths" updated successfully; old value was "/home/dld/vendor/drupal/coder/coder_sniffer"

then

drupalcs hello_world.module

worked perfectly fine.