DrupalPod icon indicating copy to clipboard operation
DrupalPod copied to clipboard

Add `phpcs` command

Open Decipher opened this issue 4 years ago • 5 comments

Is your feature request related to a problem? Please describe

As a module maintainer I want an easy way to lint Drupal coding standards.

Describe the solution you'd like

  • [ ] Add PHPCS and setup coding standards
  • [ ] Add DDev phpcs command

Describe alternatives you've considered

Additional context

It appears PHPCS is already installed and configured in the Gitpod environment, but not inside of the DDev environment.

The following command can be run:

./vendor/bin/phpcs -s --standard=Drupal,DrupalPractice --extensions=module,php,install,inc,test,info.yml,js repos/[module]

An example command for DDev: .ddev/comands/web/phpcs

#!/bin/bash

## Description: Run PHP_CodeSniffer
## Usage: phpcs [flags] [args]
## Example: "ddev phpcs contrib/module/druxt"

cd web

php ../vendor/bin/phpcs -s --standard=Drupal,DrupalPractice --extensions=module,php,install,inc,test,info.yml,js $@

Decipher avatar Oct 01 '21 03:10 Decipher

If it's in vendor/bin... that means it's in the code, and also inside the container. So not understanding what you're saying about not being able to run it inside the container.

rfay avatar Oct 01 '21 03:10 rfay

The issue is the Drupal coding standards aren't installed in DDev.

ERROR: the "Drupal" coding standard is not installed. The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz and Zend

But they are installed in the Gitpod environment.

I also haven't confirmed if PHPCS is generally available, or if it's the specific environment or PR that I'm starting from

Decipher avatar Oct 01 '21 03:10 Decipher

You wouldn't install the Drupal coding standards in "ddev" would you? You'd install them in the project?

rfay avatar Oct 01 '21 03:10 rfay

There are good reasons to install these things globally where we're trying to leave the code "as is", like when testing a vanilla drupal install.

Here's how to add phpcs and coder globally, https://stackoverflow.com/questions/61870801/add-global-phpcs-and-drupal-coder-to-ddev-in-custom-dockerfile

rfay avatar Oct 01 '21 04:10 rfay

We looked into PHPCS while getting the recommended VSCode extensions for Drupal development - https://github.com/shaal/DrupalPod/pull/30

shaal avatar Oct 01 '21 13:10 shaal