sirbrillig / phpcs-variable-analysis

Find undefined and unused variables with the PHP Codesniffer static analysis tool.
Other
135 stars 14 forks source link

Feature: documentation for installation on Visual Studio Code #74

Open vivaldus opened 5 years ago

vivaldus commented 5 years ago

I've been fiddling around with VSCode plugins, phpcs config, and integrating this plugin for several hours now. I've never used phpcs before and find the whole ecosystem quite confusing. It would be really helpful to see a step-by-step guide to get Variable Analysis working in VSCode. Simply put, I'd like to see VSCode highlight variable typos as soon as they happen. Thanks.

sirbrillig commented 5 years ago

That's a good idea! Here's my notes from when I last set this up for VSCode, which may help you for right now, but a proper section of the README would be best.

Visit the extension page for VSCode phpcs and click "Install". Once it has installed, click "Reload" in the VSCode extension window or just reload the window by opening the command palette (command-P) and typing "reload".

Once the extension is installed, there are several ways to add the ruleset to a project. The simplest is probably to add a composer.json file to your project directory, then install following the instructions on the README:

composer require --dev dealerdirect/phpcodesniffer-composer-installer composer require --dev sirbrillig/phpcs-variable-analysis

Next, create a file like this as a phpcs.xml file in your project directory:

<?xml version="1.0"?>
<ruleset name="MyStandard">
    <rule ref="VariableAnalysis"/>
</ruleset>

After that, it should just work!