{"id":15492314,"url":"https://github.com/tommcfarlin/phpcs-wpcs-vscode","last_synced_at":"2025-04-15T06:08:41.654Z","repository":{"id":139745358,"uuid":"74045777","full_name":"tommcfarlin/phpcs-wpcs-vscode","owner":"tommcfarlin","description":"How to install PHP CodeSniffer and the WordPress Coding Standard Rules in Visual Studio Code.","archived":false,"fork":false,"pushed_at":"2020-07-31T14:13:27.000Z","size":8,"stargazers_count":198,"open_issues_count":4,"forks_count":18,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-15T06:08:37.309Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tommcfarlin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-17T16:29:14.000Z","updated_at":"2025-03-24T09:49:14.000Z","dependencies_parsed_at":"2023-04-21T17:30:47.424Z","dependency_job_id":null,"html_url":"https://github.com/tommcfarlin/phpcs-wpcs-vscode","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tommcfarlin%2Fphpcs-wpcs-vscode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tommcfarlin%2Fphpcs-wpcs-vscode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tommcfarlin%2Fphpcs-wpcs-vscode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tommcfarlin%2Fphpcs-wpcs-vscode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tommcfarlin","download_url":"https://codeload.github.com/tommcfarlin/phpcs-wpcs-vscode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016627,"owners_count":21198833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T08:00:17.762Z","updated_at":"2025-04-15T06:08:41.631Z","avatar_url":"https://github.com/tommcfarlin.png","language":null,"readme":"# PHP CodeSniffer and WordPress Coding Standards with VS Code\n\n_Last Updated 2020-07-31 by @tommcfarlin_\n\nThis guide is meant to provide all of the steps necessary to easily get up and running with PHP CodeSniffer, the WordPress Coding Standard ruleset, and Visual Studio Code.\n\n![Visual Studio Code](https://tommcfarlin.com/wp-content/uploads/2020/07/visual-studio-code-974x1024.png)\n\nAll of the resources used in this guide are linked at the bottom. This guide is also licensed [MIT](https://github.com/tommcfarlin/phpcs-wpcs-vscode/blob/master/LICENSE). If you'd like to contribute, then please feel free to open issues or issue pull requests. I'll be happy to merge them and also add your username to [CONTRIBUTING](https://github.com/tommcfarlin/phpcs-wpcs-vscode/blob/master/CONTRIBUTING.md).\n\nIf you're looking for corresponding blog posts, please see:\n1. [Setting Up PHP CodeSniffer in Visual Studio Code](https://tommcfarlin.com/php-codesniffer-in-visual-studio-code)\n2. [Setting Up PHP CodeSniffer Per Project](https://tommcfarlin.com/php-codesniffer-per-project/)\n\nAs always, don't forget to checkout the [CHANGELOG](https://github.com/tommcfarlin/phpcs-wpcs-vscode/blob/master/CHANGELOG.md) to track everything that's changed since the initial release of this guide.\n\n______\n\n## 1. Verifying PHP\n\nThe following steps assume you have PHP installed and globally accessible on your system.\nYou can test this by entering the following command in the terminal:\n\n```\n$ php -v\n```\n\nAnd you should see something like this:\n\n```\nPHP 7.4.7 (cli) (built: Jun 12 2020 00:04:10) ( NTS )\nCopyright (c) The PHP Group\nZend Engine v3.4.0, Copyright (c) Zend Technologies\n    with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans\n    with Zend OPcache v7.4.7, Copyright (c), by Zend Technologies\n```\n\nIf you're looking for how to use a different version of PHP installed elsewhere on your system, this is not the guide for that. If, however, you're curious as to _where_ the version of PHP you're using is stored, you can enter:\n\n```\n$ which php\n```\n\nAnd you should see something similar to this:\n\n```\n/usr/local/bin/php\n```\n\nThat should give you enough information for the rest of this guide.\n\n## 2. Installing Composer\n\nInstalling Composer globally means that you'll be able to access it from anywhere on your system (that is, in any directory regardless of where you are). To do this, you can read the [manual](https://getcomposer.org/doc/00-intro.md) or follow the quick steps below (which summarize the manual, anyway):\n\n1. Grab [the latest snapshot](https://getcomposer.org/composer.phar) of Composer. Save it somewhere you'll remember.\n2. Move the file you just downloaded to the `/usr/local/bin/` directory on your machine.\n\nTo do this, open your terminal navigate to the directory where you downloaded `composer.phar`. Move the file to the diretory mentioned above by issuing the following command:\n\n```\n$ mv composer.phar /usr/local/bin/composer\n```\n\nAnd now you can access Composer from anywhere in your system. To do try it out, enter the following command in your terminal:\n\n```\n$ composer about\n```\n\nYou should see something like this:\n\n```\nComposer - Package Management for PHP\nComposer is a dependency manager tracking local dependencies of your projects and libraries.\nSee https://getcomposer.org/ for more information.\n```\n\nWith Composer globally installed, you can now install the WordPress Coding Standards rules.\n\n## 3. Installing PHP CodeSniffer\n\nFor the purposes of this document, we're installing PHP CodeSniffer on a project-by-project basis. To do this, we're going to be using Composer.\n\nFrom the integrated terminal within Visual Studio Code, enter the following command:\n\n```\n$ composer require \"squizlabs/php_codesniffer=3.*\"\n```\n\nThis will create `composer.json`, tell it where to locate the PHP CodeSniffer, and install it in a `vendor` directory. Once this is done, we need the WordPress Coding Standard ruleset.\n\n## 4. Installing the WordPress Coding Standards Rules\n\nI recommend placing the rules in a directory you can refer to often. Personally, I use a `projects` directory to manage all of my work.\n\nFrom within your directory of choice, say `/projects`, enter the following command in the terminal:\n\n```\n$ composer create-project wp-coding-standards/wpcs:dev-master --no-dev\n```\n\nThis will create a `wpcs` directory in your `projects` directory and it makes it easy to tell each project where the WordPress Coding Standards are stored because, remember, we'll be using Composer on a project-by-project basis.\n\n## 5. Tell PHPCS About WPCS\n\nFrom within Visual Studio's integrated terminal, make sure that you're in your project's directory and then issue the following command:\n\n```\n$ ./vendor/bin/phpcs --config-set installed_paths /path/to/dropbox/projects/wpcs\n```\n\nAnd this will tell your project's copy of PHPCS where the WordPress Coding Standards are.\n\n## 6. Update User Settings\n\nFinally, we need to let Visual Studio what we're going to be using to sniff out the code in our project and what rules to use. This is really easy to do. In Visual Studio, hit the `⌘,` (or whatever your operating system uses) command to open `settings.json`.\n\nMake sure the file looks like the following (though you may need to tweak based on your existing settings)\n\n```json\n// Place your settings in this file to overwrite the default settings\n{\n    // PHPCS\n    \"phpcs.enable\": true,\n    \"phpcs.standard\": \"WordPress\",\n    \"phpcs.executablePath\": \"./vendor/bin/phpcs\",\n    \"phpcs.showWarnings\": true,\n    \"phpcs.composerJsonPath\": \"composer.json\",\n}\n```\n\nAnd this will enable PHPCS and will also tell it to use the standard WordPress ruleset. If this doesn't start working on the code your have automatically, then restart Visual Studio Code.\n___\n\n## Resources\n\n- [Visual Studio Code](https://code.visualstudio.com/)\n- [Getting Started](https://getcomposer.org/doc/00-intro.md)\n- [The Latest Composer Snapshot](https://getcomposer.org/composer.phar)\n- [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)\n- [WordPress Coding Standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards)\n- [Setting Up PHP CodeSniffer in Visual Studio Code](https://tommcfarlin.com/php-codesniffer-in-visual-studio-code)\n- [Setting Up PHP CodeSniffer Per Project](https://tommcfarlin.com/php-codesniffer-per-project/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftommcfarlin%2Fphpcs-wpcs-vscode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftommcfarlin%2Fphpcs-wpcs-vscode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftommcfarlin%2Fphpcs-wpcs-vscode/lists"}