Difference between revisions of "Setup PHP CodeSniffer"
From GLMWiki
(→Instructions for linux) |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
== Instructions for linux == | == 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) == | == 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": "/ | + | "phpcs.executablePath": "/home/{user name}/bin/phpcs", |
"phpcs.standard": "WordPress-Extra", | "phpcs.standard": "WordPress-Extra", | ||
... | ... |
Latest revision as of 09:24, 19 December 2019
Contents
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.