Magento 2 – Install and Check Coding Standards for Marketplace Extension

magento2marketplace

I want to check My Extension's coding standard for Magento Marketplace before submitting it on **Magento Marketplace*. Can anyone tell me how can I install coding standard in My Local Environment and check my extension whether this extension is eligible or not for Magento Marketplace code standard.

Thanks In Advance..!

Best Answer

Magento use EQP Coding Standard tool for checking the coding standard of a module.https://github.com/magento/marketplace-eqp

Magento this tool used basically using PHP_CodeSniffer tool.

If you want to in run EQP Coding Standard on your local system, then follow steps:

  1. Go to your Magento root directory, install this too using composer:

composer create-project --repository=https://repo.magento.com magento/marketplace-eqp magento-coding-standard

  1. Then go to this tool directly using cd magento-coding-standard

  2. run Composer update command composer install which will update module dependency packages. Also set config path specific PHP version set paths to php binary dir

vendor/bin/phpcs --config-set php7.0_path /path/to/your/php7

  1. After that, you can use below command for checkout code start of your module from magento-coding-standard folder

    php vendor/bin/phpcs /path/to/your/extension --standard=MEQP2

use MEQP2 for magento2 extension.

Example:

php vendor/bin/phpcs /var/www/html/MagentoProkect/app/code/DevAmitbera/CustomModule --standard=MEQP2 --extensions=php,phtml

Here i give full path of my extension /var/www/html/MagentoProkect/app/code/DevAmitbera/CustomModule

4.1. If you use windows and face some path must be translated related warning in command line then try below solution. Install Cygwin console from https://cygwin.com and then go to magento-coding-standard directory and run below command.

vendor/bin/phpcs F:/xampp/htdocs/magento2/app/code/DevAmitbera/CustomModule --standard=MEQP2 --severity=10 --extensions=php,phtml

  1. After That, I have tun code sniffer auto fixer command which is basic code standards issue.

php vendor/bin/phpcbf /path/to/your/extension -extensions=php,phtml --standard=MEQP2

Example:

php vendor/bin/phpcbf /var/www/html/app/code/DevAmitbera/CustomModule --standard=MEQP2 --extensions=php,phtml

After re-run Step 4 command for check out the rest of error which you need to fix yourself manually.

Related Topic