Which steps need to follow For Standard Extension Development for Magento 2

For a Magento 2 extension, you should be following the Magento EQP (Extension Quality Program) code standards. Magento provides a tool to validate the PSR-2 code standards and most of Magento's added standards on top of that. Magento has provided the package validation tool, Which detects any kind of packaging errors to reduce the module rejections from the Marketplace.

Steps which need to follow For Standard Extension Development for Magento 2 :

  • 1) must have composer.json in root folder of extension(Eg. app/code/Vendor/Module/composer.json)
  • 2) must have registration.php in root folder of extension (Eg. app/code/Vendor/Module/registration.php)
  • 3) Do not use $_REQUEST, $_POST directly
  • 4) Never end class file with ending php tag ?>
  • 5) Remove unnecessory code and comments
  • 6) Use spaces for indentation
  • 7) check with phpcs coding standard and remove all errors, Refer Coding standard tab
  • 8) Must pass severity=10 while chicking coding standard with MEQP2, Refer coding standard
  • 9) do compilation and resolve all errors
  • 10) validate_m2_package_v2

Follow the below steps to validate your package with "validate_m2_package.php" :

Clone the repository https://github.com/magento/marketplace-tools or Download the file validate_m2_package.php
Now place your module zipped file in the same folder where you placed the previous file.
Note: To zip your package, navigate to root path of your module i.e /app/code/Vendor Name/Module Name/ and then zip your package. Make sure composer.json remains in the root path of your zipped package.

Now execute the following command
$ <path_to_php> validate_m2_package.php -d vendor-modulename.zip

where <path_to_php> is the path to php compiler and vendor-modulename.zip should be name of your module zipped file.

for example:
php validate_m2_package.php -d modulename.zip