Skip to content

Instantly share code, notes, and snippets.

@dakala
Last active October 28, 2021 19:31
Show Gist options
  • Save dakala/d3c0f9ee1d13011f8fbd80a13b8c6a8f to your computer and use it in GitHub Desktop.
Save dakala/d3c0f9ee1d13011f8fbd80a13b8c6a8f to your computer and use it in GitHub Desktop.
Install and configure PHPCS for Drupal
#!/bin/sh
# Install drupal/coder
composer global require drupal/coder
# Register Drupal and DrupalPractice Standard with PHPCS
phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
# Colorise output
phpcs --config-set colors 1
# Go home
cd ~
# Add aliases to .bashrc
sed -i '0,/alias/s//\nalias drupalcs="phpcs --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt'"\nalias drupalbp="phpcs --standard=DrupalPractice --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt,md'"\nalias drupalcbf="phpcbf --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt,md'"\n&/' .bashrc
# Refresh
source .bashrc
@dakala
Copy link
Author

dakala commented Jun 20, 2019

Provided you have aliases defined in your .bashrc:

sed -i '0,/alias/s//\nalias drupalcs="phpcs --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt'"\nalias drupalbp="phpcs --standard=DrupalPractice --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt,md'"\nalias drupalcbf="phpcbf --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt,md'"\n&/' .bashrc works on linux

sed -i "" -e '0,/alias/s//\nalias drupalcs="phpcs --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt'"\nalias drupalbp="phpcs --standard=DrupalPractice --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt,md'"\nalias drupalcbf="phpcbf --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt,md'"\n&/' .bashrc should work on mac

@dakala
Copy link
Author

dakala commented Jun 21, 2019

The last sed command doesn't work on Mac. Best to add the aliases to your .bash_profile or .bashrc and source the file:

alias drupalcs="phpcs --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt'"
alias drupalbp="phpcs --standard=DrupalPractice --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt,md'"
alias drupalcbf="phpcbf --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt,md'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment