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

Created on 3 February 2022, almost 3 years ago
Updated 26 January 2023, almost 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.

Production build 0.71.5 2024