vscode-phpcsThis linter plugin for Visual Studio Code provides an interface to phpcs. It will be used with files that have the “PHP” language mode. InstallationVisual Studio Code must be installed in order to use this plugin. If Visual Studio Code is not installed, please follow the instructions here. Linter InstallationBefore using this plugin, you must ensure that Once phpcs is installed, you can proceed to install the vscode-phpcs plugin if it is not yet installed.
System-wide InstallationThe
Project-wide InstallationThe
Plugin Installation
Basic ConfigurationThere are various options that can be configured to control how the plugin operates which can be set in your user, workspace or folder preferences. phpcs.enable[ Scope: All | Optional | Type: boolean | Default: true ] This setting controls whether phpcs.executablePath[ Scope: All | Optional | Type: string | Default: null ] This setting controls the executable path for the phpcs.standard[ Scope: All | Optional | Type: string | Default: null ] This setting controls the coding standard used by
The following values are applicable:
phpcs.autoConfigSearch[ Scope: All | Optional | Type: boolean | Default: true ] Automatically search for any
phpcs.ignorePatterns[ Scope: All | Optional | Type: array | Default: [] ] An array of glob patterns to skip files and folders that match when linting your documents.
phpcs.ignoreSource[ Scope: All | Optional | Type: array | Default: [] ] An array of ignored sources. It could be file, gitfs or another file system of any extension
phpcs.errorSeverity[ Scope: All | Optional | Type: number | Default: 5 ] The minimum severity an error must have to be displayed. You may specify an integer value. phpcs.warningSeverity[ Scope: All | Optional | Type: number | Default: 5 ] The minimum severity a warning must have to be displayed. You may specify an integer value. phpcs.showWarnings[ Scope: All | Optional | Type: boolean | Default: true ] Control whether warnings are displayed. phpcs.showSources[ Scope: All | Optional | Type: boolean | Default: false ] Show sniff source codes in diagnostic messages. phpcs.trace.server[ Scope: User | Optional | Type: string | Default: off ] This setting controls whether the trace server is activated. Possible values you can use is Advanced Configurationphpcs.composerJsonPath[ Scope: All | Optional | Type: string | Default: composer.json ] This setting allows you to override the path to your composer.json file when it does not reside at the workspace root. You may specify the absolute path or workspace relative path to the phpcs.lintOnOpen[ Scope: All | Optional | Type: boolean | Default: true ] Lint file when open it phpcs.lintOnSave[ Scope: All | Optional | Type: boolean | Default: true ] Lint file when save it phpcs.lintOnType[ Scope: All | Optional | Type: boolean | Default: true ] Lint on every document change. Watch out! Work with big php file may cause high CPU usage. phpcs.queueBuffer[ Scope: All | Optional | Type: number | Default: 10 ] The number of files in the queue for linting. When document is linting and it has any changes, the document will be queued up or replaced in queue. phpcs.lintOnlyOpened[ Scope: All | Optional | Type: boolean | Default: true ] Lint only opened files within vscode. For better performance. Diagnosing common errorsThe phpcs report contains invalid jsonThis error occurs when something goes wrong in phpcs execution such as PHP Notices, PHP Fatal Exceptions, Other Script Output, etc, most of which can be detected as follows: Execute the phpcs command in your terminal with --report=json and see whether the output contains anything other than valid json.
AcknowledgementsThe extension architecture is based off of the Language Server Node Example. Additional inspiration comes from Atom Linter-phpcs. Contributing and LicensingThe project is hosted on GitHub where you can report issues, fork the project and submit pull requests. The project is available under MIT license, which allows modification and redistribution for both commercial and non-commercial purposes. |