This is the second part of our series guide on setup of Visual Studio Code on Mac. The first part of the guide is here. In this guide we have shown to setup WordPress debug setup. Here is part 2 of how to setup Visual Studio Code on Mac for debugging Arduino, WordPress etc and this current webpage is only for final setup for WordPress. If you want to follow our guides, you must only follow our guides – not of someone else ending up messing up the whole setup. We have tested the things many times and at the time of writing the guide we have no error. Microsoft does say the same thing – they do not have error. P
Setup Visual Studio Code on Mac For Debugging WordPress
We will show you the way which will not create issue with Atom Editor and on Command Line. From the previous guide, you have a composer.json
file located at /Users/your-user-name/.composer/composer.json
, which is /Users/abhishekghosh/.composer/composer.json
for me. If we run a cat
on it :
1 | cat /Users/abhishekghosh/.composer/composer.json |
We’ll get this output :
---
1 2 3 4 5 | { "require": { "squizlabs/php_codesniffer": "*" } } |
But I need to have that thing here too :
1 | /Users/abhishekghosh/composer.json |
So create a composer.json
at /Users/your-user-name
and copy-paste the content. Which in my case is just easy :
1 | cp /Users/abhishekghosh/.composer/composer.json /Users/abhishekghosh/composer.json |
Now run :
1 2 3 | composer update composer global show vendor/bin/phpcs --version |
There will be no error. Now install WordPress coding standard (which is actually a physical project, also available on Github) :
1 | composer create-project wp-coding-standards/wpcs:dev-master --no-dev |
You’ll get this kind of output :
1 2 3 4 5 6 7 8 9 | Created project in /Users/abhishekghosh/wpcs Loading composer repositories with package information Updating dependencies Package operations: 1 install, 0 updates, 0 removals - Installing squizlabs/php_codesniffer (3.1.0): Loading from cache Writing lock file Generating autoload files > "vendor/bin/phpcs" --config-set installed_paths ../../.. Using config file: /Users/abhishekghosh/wpcs/vendor/squizlabs/php_codesniffer/CodeSniffer.conf |
If you run :
1 | ls -al ~/wpcs/vendor/bin/phpcs |
You’ll notice a symlink. Now you’ll add another symlink :
1 | ln -s ~/wpcs/vendor/bin/phpcs /usr/local/bin/phpcs |
Add this thing to your ~/.zshrc
:
1 | export PATH="/Users/abhishekghosh/wpcs/vendor/bin:$PATH" |
Then save the file and reload :
1 | source ~/.zshrc |
Now run this command :
1 | vendor/bin/phpcs --config-set installed_paths wpcs |
Then run this command :
1 | vendor/bin/phpcs -i |
You should receive output like this :
1 | The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz, Zend, WordPress, WordPress-Core, WordPress-Docs, WordPress-Extra and WordPress-VIP |
You wanted WordPress, is not it? Now for testing, clone Hello Dolly plugin :
1 2 | cd ~ git clone https://github.com/wp-plugins/hello-dolly.git |
Run checking :
1 | vendor/bin/phpcs --standard=WordPress hello-dolly |
You’ll get output like this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | FILE: /Users/abhishekghosh/hello-dolly/hello.php -------------------------------------------------------------------------------- FOUND 16 ERRORS AFFECTING 15 LINES -------------------------------------------------------------------------------- 2 | ERROR | [ ] Missing short description in doc comment 5 | ERROR | [ ] There must be exactly one blank line after the file comment 6 | ERROR | [ ] Empty line required before block comment 15 | ERROR | [ ] You must use "/**" style comments for a function comment 46 | ERROR | [ ] Inline comments must end in full-stops, exclamation marks, or | | question marks 49 | ERROR | [ ] Inline comments must end in full-stops, exclamation marks, or | | question marks 53 | ERROR | [ ] Inline comments must end in full-stops, exclamation marks, or | | question marks 54 | ERROR | [ ] You must use "/**" style comments for a function comment 56 | ERROR | [ ] Expected next thing to be an escaping function (see Codex for | | 'Data Validation'), not '"<p id='dolly'>$chosen</p>"' 59 | ERROR | [ ] Inline comments must end in full-stops, exclamation marks, or | | question marks 62 | ERROR | [ ] Inline comments must end in full-stops, exclamation marks, or | | question marks 63 | ERROR | [ ] You must use "/**" style comments for a function comment 64 | ERROR | [ ] Inline comments must end in full-stops, exclamation marks, or | | question marks 67 | ERROR | [ ] Expected next thing to be an escaping function (see Codex for | | 'Data Validation'), not '" | | ' 82 | ERROR | [x] A closing tag is not permitted at the end of a PHP file 82 | ERROR | [x] File must end with a newline character -------------------------------------------------------------------------------- PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY -------------------------------------------------------------------------------- Time: 758ms; Memory: 8Mb |
Now start Visual Studio Code. That PHPCS extension may disturb and need disabling, reload, enabling and reload to function. You need not to modify settings in Visual Studio Code ( to access user settings click Debug icon and hit COMMAND and , ) as by default in PHPCS extension it is set to null
, which means default :
1 | https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs |
Now if you copy paste that Hello Dolly plugin’s one PHP file on Visual Studio Code and run Debug as PHP, you’ll get huge errors :
You can install extensions like this :
1 | https://marketplace.visualstudio.com/items?itemName=HvyIndustries.crane |
For the above extension you need to access user settings by clicking Debug icon and hitting COMMAND
and ,
search for what they have suggested to change, save and relaunch.
That PHPCS extension may again disturb and need disabling, reload, enabling and reload to function. That error happens as our ZSH itself load very slow and Visual Studio Code expects immediate availability.
Tagged With how to debug in visual studio mac? , setup visual studio code for arduino