Using php = 7.2
Composer = 1.7.2

Commands:-

phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml --sniffs=Drupal.Classes.UnusedUseStatement /path/to/drupal/example_module

phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml /path/to/drupal/example_module

Error:-

PHP Fatal error: Uncaught Error: Class 'Symfony\Component\Yaml\Yaml' not found in /home/lenovo/.composer/vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/NamespacedDependencySniff.php:61
Stack trace:
#0 /usr/share/php/PHP/CodeSniffer/src/Files/File.php(497): DrupalPractice\Sniffs\InfoFiles\NamespacedDependencySniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 0)
#1 /usr/share/php/PHP/CodeSniffer/src/Files/LocalFile.php(91): PHP_CodeSniffer\Files\File->process()
#2 /usr/share/php/PHP/CodeSniffer/src/Runner.php(585): PHP_CodeSniffer\Files\LocalFile->process()
#3 /usr/share/php/PHP/CodeSniffer/src/Runner.php(394): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))
#4 /usr/share/php/PHP/CodeSniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()
#5 /usr/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#6 {main}
thrown in /home/lenovo/.composer/vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/NamespacedDependencySniff.php on line 61

My composer file code:-

{
    "require": {
        "drush/drush": "10.*",
        "drupal/coder": "^8.3",
        "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
        "twig/twig": "1.42.4"
    }
}

Comments

rohit-drupal created an issue. See original summary.

rohit-rajput-sahab’s picture

Version: 8.x-3.1 » 8.x-3.7
klausi’s picture

Status: Active » Fixed

as you can see the wrong PHPCS class is used from /usr/share/php/PHP/CodeSniffer instead of from your composer folder at /home/lenovo/.composer/vendor.

Please uninstall PHP CodeSniffer from /usr/share/php/PHP and try again.

rohit-rajput-sahab’s picture

Thank you for your comments. I uninstalled PHP CodeSniffer from /usr/share/php/PHP and run command. It's working without any error but I removed module name in mymodule.info.yml file and run below commands. The command nothing showing any error and warnings.

Please help me.

Commands:-

phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml --sniffs=Drupal.Classes.UnusedUseStatement /path/to/drupal/example_module

phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml /path/to/drupal/example_module

rohit-rajput-sahab’s picture

Status: Fixed » Active
Arkener’s picture

The module name currently isn't one of the keys that's being validated on Drupal 8 projects. Could you add the following to your *.info.yml file and check again using phpcs --standard=DrupalPractice --extensions=yml /path/to/drupal/example_module

dependencies:
  - system

This should display the following output:

FILE: foo.info.yml
----------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------
 8 | WARNING | All dependencies must be prefixed with the project name, for example "drupal:"
rohit-rajput-sahab’s picture

mymodule.info.yml file code is below
type: module
description: 'XXXXXXXXXXXXXXXxx.'
package: XXXXXXXXXXXX API
core: 8.x

And I ran "phpcs --standard=DrupalPractice --extensions=yml /path/to/drupal/mumodule/mymodule.info.yml"

Nothing is showing

Arkener’s picture

The module name currently isn't one of the keys that's being validated, which means your given info file is valid according to the DrupalPractice standard. Could you change your info file to following and check again:

type: module
description: 'XXXXXXXXXXXXXXXxx.'
package: XXXXXXXXXXXX API
core: 8.x

dependencies:
  - system
rohit-rajput-sahab’s picture

@Arkener
Ok, thanks for "*.info.yml"

What about other YML files like "*libraries.yml", "*.links.menu.yml", "*.services.yml", and "*.routing.yml" etc.

Arkener’s picture

All YAML files in the given directory will be scanned if you pass the yml extension phpcs --standard=DrupalPractice --extensions=yml /path/to/drupal/mymodule. This includes the libraries, menu, services and routing files. The scanned files can be displayed using the verbose option, for example phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml /path/to/drupal/example_module -v

klausi’s picture

Status: Active » Fixed

Thanks for your support here Arkener! With that I think we can close this, let me know if there are still questions.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.