Skip to content
NewRedesigned blogFeedback
Jigar Karangiya

How to configure Magento 2 coding standards in visual studio code?

Magento uses its own code standard, You can configure Magento 2 Coding standards easily in VS code using this easy steps.

How to configure Magento 2 coding standards in visual studio code?
Written by
JKJigar Karangiya
Published
Reading time
2 min read

Jigar Karangiya · · 2 min read

In this blog post, we will see how to configure Magento 2 coding standards in VS Code.

Maintaining coding standards is crucial for Magento 2 developers to create clean, maintainable, and high-quality code. By configuring coding standards in your preferred development environment, like VS Code, you can automate code formatting and ensure consistency across your projects. This will help you enhance your development workflow and ensure compliance with the Magento community’s guidelines.

Developers should consistently use PHP_CodeSniffer (opens in new tab) to enhance the readability of the code and ensure that it meets the Magento Coding Standard. PHP_CodeSniffer (opens in new tab) is the most popular tool in use throughout the PHP development community. It provides the mechanism for checking code compliance with specific coding standards.

Magento uses its own code standard, which you can find on git:

https://github.com/magento/magento-coding-standard (opens in new tab)

The set of rules is located in ruleset.xml (opens in new tab) the file of the Magento Coding Standard (opens in new tab).

So, Let’s start with configuring Magento 2 coding standards with our VS Code.

Step 1: PHPCS Plugin Installation

  1. Open Visual Studio Code.
  2. Press Ctrl+Shift+X to open the Extensions Menu.
  3. Search for PHPCS in the search bar and install “phpcs” extension provided by “shevaua”
Figure 01

4. Click on the install button and restart VS code when prompted.

Step 2: Installing Magento 2 Coding Standards

The best way to use Magento coding standards is to setup it up globally using Composer.

  • You can install it using the below command.

    composer create-project magento/magento-coding-standard --stability=dev magento-coding-standard

  • To verify the installation run the below command.

    php vendor/bin/phpcs -i

  • Once installed, you can run phpcs from the command line to analyze your code

    php vendor/bin/phpcs --standard=Magento2 app/code/VendorName/ModuleName

Step 3: Configure VS code for Magento 2 Standards

We are now done with the installation of Magento 2 coding standards.

Let’s start configuring and using it with our visual studio code.

  1. Press CTRL + SHIFT + P and search for “Open User Settings (JSON) ” and hit enter.

  2. It will load VS code settings in JSON format.

  3. Insert the below line and specify the path for your coding standard path and ruleset file.

    "phpcs.executablePath": "Path-To-InstallationDir/vendor/bin/phpcs", "phpcs.standard": "Path-To-InstallationDir/Magento2/ruleset.xml"

Figure 02Configuring VS Code with Magneto 2 coding standards
Configuring VS Code with Magneto 2 coding standards

For example, in my case it will be like this :

text
"phpcs.executablePath": "/home/jigar_karangiya/htdocs/magento-coding-standard/vendor/bin/phpcs",
"phpcs.standard": "/home/jigar_karangiya/htdocs/magento-coding-standard/Magento2/ruleset.xml",

4) Save it and restart your VS Code.

  1. Now open any Magento 2 project file which you are working on. It will show suggestions and warnings as below with an underline.
Figure 03Magento 2 Coding Standards Suggestions
Magento 2 Coding Standards Suggestions

You may also like :

How to Get a list of all observers of specific events in Magento 2

Get Company Admin using company ID programmatically Magento 2 B2B

That’s it. Happy Coding !!

Keep reading
All posts

01 · 10 min · Shares Adobe Commerce Core

Adobe Commerce Agentic Capabilities, Q4 2026

Five agentic releases for Adobe Commerce: LLM product discovery, Brand Visibility, the Shopper MCP server, Brand Concierge, and Experience Workspace. What each one does, which editions get it, and when.

10 min

03 · 3 min · Shares Adobe Commerce Core

Conditions for Collections in Magento 2

Collections in Magento 2 (Now Adobe Commerce), are among the most powerful tools for retrieving and manipulating data directly from the database.

3 min

Newsletter

New Magento tutorials, straight to your inbox

Code examples, performance tips, and fixes for common Magento issues. No spam.

Subscribe