Last active
October 28, 2021 19:31
-
-
Save dakala/d3c0f9ee1d13011f8fbd80a13b8c6a8f to your computer and use it in GitHub Desktop.
Install and configure PHPCS for Drupal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
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 linuxsed -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