I’ve been trying to get the WordPress Coding Standards playing nicely with Visual Studio Code (I had it working on my Mac, but I’ve since moved to Elementary OS and everyone knows that configuring things you haven’t looked at in years is the most fun ever).

I’d tried it a couple of months ago and gave up because I was under the gun for a project, but today (naturally) seemed like the right time to jump in again. I followed along with this guide and was generally finding it useful, but when I was “done”… still no dice.

Instead, I had the lovely Referenced sniff "PSR12.Keywords.ShortFormTypeKeywords" does not exist error. Googling didn’t really help because there was only one result, and it was just someone’s error log (hi, Danny Froberg! ?️).

Lots of Googling and tangent-following later, I figured out what the issue was: my version of PHP_CodeSniffer (PHPCS) was out of date; the ShortFormTypeKeywords sniff was added in 3.3.0 but I was running 3.2.x.

Wait, why was I running that? I’d just installed a fresh copy! However, phpcs --version told me quite clearly that I was wrong.

Well, more specifically, I was looking in the wrong place. I’d followed the instructions to install PHPCS with Composer, but which phpcs identified another install, one in /usr/bin/phpcs. I definitely didn’t install that today, but I’m guessing it was a holdover from my previous attempt.

Much trial-and-error later, I determined it was probably installed with PEAR, and eventually got it uninstalled with pear uninstall PHP_CodeSniffer, updated Visual Studio Code’s settings.json with the accurate path (I likely could have done just that and skipped uninstalling), and at long last, am getting reminders to use Yoda conditions and fill in my DocBlocks. Victory!

1 Comment

  1. Tom on March 23, 2020 at 12:12 pm

    I just experienced this exact issue, so thanks for saving me a few hours of head scratching! For me I’d installed via apt, which is still on 3.2.x.

Leave a Comment





This site uses Akismet to reduce spam. Learn how your comment data is processed.