Thursday, July 13, 2023

Drupal coding standards check with PHPCS (phpcodesniffer) in Drupal 9

 Step 1: We need to run the command on drupal root folder

composer require drupal/coder


Step 2:- after install is done you can check the phpcs file inside the vendor/bin folder

Step 3: Now we can check whether it's working or not simply run the command.

./vendor/bin/phpcs --help


Step 4:- If it's working we can check the code error for the command.

./vendor/bin/phpcs web/modules/custom (need to check custom module code)


Step 5:- How we can remove the file path like web/module/custom I am just run the command ./vendor/bin/phpcs and get the output.

1. We need to create phpcs.xml file for root folder.

2. Copy the Xml code click here and current the root path of folder which need to be check in the code.


3. Now we get the so many Error so run the command PHPCBF which is beautify the code.


4. Run the command 

./vendor/bin/phpcbf


5, now run again ./vendor/bin/phpcs and manually fixed the issue.


No comments:

Post a Comment

If you have any problem please let me know.