shaal / DrupalPod

Start Drupal contributions with 1 click.
https://shaal.github.io/DrupalPod
MIT License
164 stars 54 forks source link

Add `phpcs` command #45

Open Decipher opened 2 years ago

Decipher commented 2 years ago

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

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 $@
rfay commented 2 years ago

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.

Decipher commented 2 years ago

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

rfay commented 2 years ago

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

rfay commented 2 years ago

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

shaal commented 2 years ago

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