How to Add WordPress Coding Standards in PHP_CodeSniffer

In this tutorial, you will learn how to add WordPress Coding Standards in PHP_CodeSniffer.

Prerequisites

WordPress Coding Standards have the ruleset of PHP_CodeSniffer. The ruleset is a set of sniffs that looks for things that are wrong and tells you about them so that you can fix them. So if we go to GitHub and look up the WordPress Coding Standards and navigate to it, we find the ruleset having a bunch of instructions for PHP_CodeSniffer to follow. Now ruleset tells PHP_CodeSniffer what to do.

To get this ruleset on your computer you have to use git so I am assuming that you have already installed git on your computer and we will install it as a standalone set so you can use it globally. Now copy & paste the following command which cloned the master branch and we will put it in wpcs directory on our computer. In my case, I am on my D Drive and I have a special directory in my D Drive called utilities so I will change my directory by using the window command cd and navigate to utilities folder i.e.

cd utilities

and clone them.

git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git wpcs

Now we have to tell PHP_CodeSniffer to go and look at this ruleset and to do that we will run a command phpcs and set some configuration with –config-set specifically, we want you to point at a new path with installed_paths and the path where we cloned it i.e.

phpcs --config-set installed_paths "D:\utilities\wpcs"

After run above command, we will get the following output.

Config value "installed_paths" updated successfully;

Now if we type the following command and hit enter.

phpcs -i

We will see that we have all of the WordPress Coding Standards available via the command line on PHP_CodeSniffer.

Related Post

How to Install PHP_CodeSniffer Using Composer

In this tutorial, you will learn how to install PHP_CodeSniffer using Composer on Windows.

How to Add Yii2 Coding Standards in PHP_CodeSniffer

In this tutorial, you will learn how to add Yii2 Coding Standards in PHP_CodeSniffer.

Leave a Reply