Skip to content

Instantly share code, notes, and snippets.

@parthnvaswani
Last active February 9, 2023 12:30
Show Gist options
  • Save parthnvaswani/e627500e81f9d3b3f5a6bc7298797d91 to your computer and use it in GitHub Desktop.
Save parthnvaswani/e627500e81f9d3b3f5a6bc7298797d91 to your computer and use it in GitHub Desktop.
Setup PHPCS for WordPress Development

Install PHPCS using composer:

composer g require --dev automattic/vipwpcs dealerdirect/phpcodesniffer-composer-installer -W

Note: If you do not have composer install it using brew:

brew install composer

Edit your .zshrc file and add the following line at the end:

export PATH="$HOME/.composer/vendor/bin:$PATH"

Note: .zshrc exists in the home folder to append the line use following commands:

cd ~

cat >> .zshrc

export PATH="$HOME/.composer/vendor/bin:$PATH"

^C

Verify the path by opening new terminal and running the following:

which phpcs

/Users/<username>/.composer/vendor/bin/phpcs

Execute the following commands for adding the required coding standards:

composer g config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer g require --dev dealerdirect/phpcodesniffer-composer-installer:"^0.7" phpcompatibility/phpcompatibility-wp:"*"

Add phpcs and path to vscode:

  • Open vscode
  • Install the phpcs extension from the marketplace.
  • Press CMD+, to open the settings tab.
  • Search for "phpcs:Executable Path" and add "/Users/<username>/.composer/vendor/bin/phpcs" to it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment