Difference between revisions of "Setup PHP CodeSniffer"

From GLMWiki
Jump to: navigation, search
(Instructions for linux)
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
== Instructions for linux ==
 
== Instructions for linux ==
1. Setup a bin directory in your home folder.
+
* Setup a bin directory in your home folder.
2. Add your bin directory to your PATH variable.
+
* Add your bin directory to your PATH variable.
3. Download phpcs and phpcbf files into your bin directory.
+
* Download phpcs and phpcbf files into your bin directory.
4. Rename them to phpcs and phpcbf.
+
* Rename them to phpcs and phpcbf.
5. Test that they work and files are executable by your user.
+
* Test that they work and files are executable by your user.
  
 
== Setup Wordpress Coding Standards (modified by Glma) ==
 
== Setup Wordpress Coding Standards (modified by Glma) ==
 
1. Clone our forked copy of Wordpress Coding Standards to a directory named wpcs somewhere in your home directory.
 
1. Clone our forked copy of Wordpress Coding Standards to a directory named wpcs somewhere in your home directory.
  git clone ssh://git@bitbucket.gaslightmedia.com:7999/doc/wordpress-coding-standards.git wpcs
+
  git clone <nowiki>ssh://git@bitbucket.gaslightmedia.com:7999/doc/wordpress-coding-standards.git</nowiki> wpcs
 
2. Add its path to the PHP_CodeSniffer configuration
 
2. Add its path to the PHP_CodeSniffer configuration
 
  phpcs --config-set installed_paths {your path to wpcs}/wpcs
 
  phpcs --config-set installed_paths {your path to wpcs}/wpcs
Line 25: Line 25:
 
{
 
{
 
     ...
 
     ...
     "phpcs.executablePath": "/Users/javorszky/.composer/vendor/bin/phpcs",
+
     "phpcs.executablePath": "/home/{user name}/bin/phpcs",
 
     "phpcs.standard": "WordPress-Extra",
 
     "phpcs.standard": "WordPress-Extra",
 
     ...
 
     ...

Latest revision as of 09:24, 19 December 2019

Setup PHP CodeSniffer

Instructions for linux

  • Setup a bin directory in your home folder.
  • Add your bin directory to your PATH variable.
  • Download phpcs and phpcbf files into your bin directory.
  • Rename them to phpcs and phpcbf.
  • Test that they work and files are executable by your user.

Setup Wordpress Coding Standards (modified by Glma)

1. Clone our forked copy of Wordpress Coding Standards to a directory named wpcs somewhere in your home directory.

git clone ssh://git@bitbucket.gaslightmedia.com:7999/doc/wordpress-coding-standards.git wpcs

2. Add its path to the PHP_CodeSniffer configuration

phpcs --config-set installed_paths {your path to wpcs}/wpcs

3. Test phpcs finds it using 'phpcs -i' 4. Set WordPress as the default standard using

phpcs --config-set default_standard WordPress

Visual Studio Code

Install and enable the phpcs extension by Ioannis Kappas (ikappas.phpcs).

In your user settings – CMD+, on Mac or Preferences -> Settings – set these two variables:

{
    ...
    "phpcs.executablePath": "/home/{user name}/bin/phpcs",
    "phpcs.standard": "WordPress-Extra",
    ...
}

Again, the executablePath should be the result of which phpcs.

Restart VSCode, and you should have code standards enabled.