php sniffer visual studio code

PHP Sniffer & Beautifier

Samuel Hilson

PHP Sniffer & Beautifier for VS Code

php sniffer visual studio code. Смотреть фото php sniffer visual studio code. Смотреть картинку php sniffer visual studio code. Картинка про php sniffer visual studio code. Фото php sniffer visual studio code php sniffer visual studio code. Смотреть фото php sniffer visual studio code. Смотреть картинку php sniffer visual studio code. Картинка про php sniffer visual studio code. Фото php sniffer visual studio code php sniffer visual studio code. Смотреть фото php sniffer visual studio code. Смотреть картинку php sniffer visual studio code. Картинка про php sniffer visual studio code. Фото php sniffer visual studio code

This linter plugin for Visual Studio Code provides an interface to phpcs & phpcbf. It will be used with files that have the “PHP” language mode. This extension is designed to use auto configuration search mechanism to apply rulesets to files within a workspace. This is useful for developers who work with many different projects that have different coding standards.

Installation

Visual Studio Code must be installed in order to use this plugin. If Visual Studio Code is not installed, please follow the instructions here.

Usage

or keyboard shortcut alt+shift+f vs code default formatter shortcut

Format on save

Multi-Root Workspace Support

This extension now fully supports Multi-Root Workspaces. The extension previously used the first root folder in your workspace to configure and run both phpcs and phpcbf. The new system allows each workspace to be configured and run independently with respect to the root folder of the open file being sniffed. This means you can have phpcs functionality in one folder and have it disabled in another within a workspace.

Linter Installation

Before using this plugin, you must ensure that phpcs is installed on your system. The preferred method is using composer for both system-wide and project-wide installations.

Once phpcs is installed, you can proceed to install the vscode-phpsab plugin if it is not yet installed.

NOTE: This plugin can detect whether your project has been set up to use phpcbf via composer and use the project specific phpcs & phpcbf over the system-wide installation of phpcs & phpcbf automatically. This feature requires that both composer.json and composer.lock file exist in your workspace root or the phpsab.composerJsonPath in order to check for the composer dependency. If you wish to bypass this feature you can set the phpsab.executablePathCS and phpsab.executablePathCBF configuration settings.

System-wide Installation

The phpcs linter can be installed globally using the Composer Dependency Manager for PHP.

Require phpcs package by typing the following in a terminal:

You must specifically add the phpcs and phpcbf that you want to used to the global PATH on your system for the extension to auto detect them or set the executablePath for phpcs and phpcbf manually.

Project-wide Installation

The phpcs linter can be installed in your project using the Composer Dependency Manager for PHP.

Require phpcs package by typing the following at the root of your project in a terminal:

Plugin Installation

Basic Configuration

There are various options that can be configured to control how the plugin operates which can be set in your user, workspace or folder preferences.

phpsab.fixerEnable

[ Scope: Resource | Optional | Type: boolean | Default: true ]

This setting controls whether phpcbf fixer is enabled.

phpsab.fixerArguments

[ Scope: Resource | Optional | Type: string[] | Default: [] ]

Passes additional arguments to phpcbf runner.

phpsab.snifferEnable

[ Scope: Resource | Optional | Type: boolean | Default: true ]

This setting controls whether phpcs sniffer is enabled.

phpsab.snifferArguments

[ Scope: Resource | Optional | Type: string[] | Default: [] ]

Passes additional arguments to phpcs runner.

phpsab.executablePathCS

[ Scope: Resource | Optional | Type: string | Default: null ]

NOTE for Windows users: If the linter is installed globally, you must set the path to make this plugin work (example below). After saving this setting, don’t forget to reload VSCode!

phpsab.executablePathCBF

[ Scope: Resource | Optional | Type: string | Default: null ]

NOTE for Windows users: If the linter is installed globally, you must set the path to make this plugin work (example below). After saving this setting, don’t forget to reload VSCode!

phpsab.standard

[ Scope: Resource | Optional | Type: string | Default: null ]

The following values are applicable:

You may set the default_standard used by phpcbf using the following command:

or when using composer dependency manager from the root of your project issue the following command:

After you install the custom coding standard, you can make it available to phpcbf by issuing the following command:

or when using composer dependency manager from the root of your project issue the following command:

The setting can be set to the absolute path to a custom coding standard:

or you can use the path to a custom ruleset:

The setting can be set to your workspace relative path to a custom coding standard:

or you can use the path to your project’s custom ruleset:

phpsab.autoRulesetSearch

[ Scope: Resource | Optional | Type: boolean | Default: true ]

NOTE: This option does not apply for unsaved documents (in-memory). Also, the name of files that are searched for is configurable in this extension.

phpsab.allowedAutoRulesets

[ Scope: Resource | Optional | Type: array | Default: [] ]

An array of filenames that could contain a valid phpcs ruleset.

phpsab.snifferMode

[ Scope: All | Optional | Type: string | Default: onSave ]

onSave : The Sniffer will only update diagnostics when the document is saved.

onType : The Sniffer will update diagnostics as you type in a document.

phpsab.snifferTypeDelay

[ Scope: All | Optional | Type: number | Default: 250 ]

When snifferMode is onType this setting controls how long to wait after typing stops to update. The number represents milliseconds.

phpsab.snifferShowSources

[ Scope: All | Optional | Type: boolean | Default: false ]

Determines if the Sniffer includes the source of the diagnostic data with error messages.

Advanced Configuration

phpsab.composerJsonPath

[ Scope: Resource | 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 composer.json file.

Diagnosing common errors

phpsab.debug

[ Scope: All | Optional | Type: boolean | Default: false ]

Write debug information to the PHP Sniffer & Beautifier output channel and enable the display extra notices.

The phpcs report contains invalid json

This 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:

Acknowledgements

This extension is based off of the phpcs extension created by Ioannis Kappas, the PHP Sniffer extension create by wongjn and the existing phpcbf extension by Per Søderlind. It uses some portions of these extensions to provide the phpcs & phpcbf functionality with auto config search.

Contributing and Licensing

The project is hosted on GitHub where you can report issues, fork the project and submit pull requests. See the development guide for details.

The project is available under MIT license, which allows modification and redistribution for both commercial and non-commercial purposes.

Источник

phpcs

Ioannis Kappas

vscode-phpcs

This linter plugin for Visual Studio Code provides an interface to phpcs. It will be used with files that have the “PHP” language mode.

Installation

Visual Studio Code must be installed in order to use this plugin. If Visual Studio Code is not installed, please follow the instructions here.

Linter Installation

Before using this plugin, you must ensure that phpcs is installed on your system. The preferred method is using composer for both system-wide and project-wide installations.

Once phpcs is installed, you can proceed to install the vscode-phpcs plugin if it is not yet installed.

NOTE: This plugin can detect whether your project has been set up to use phpcs via composer and use the project specific phpcs over the system-wide installation of phpcs automatically. This feature requires that both composer.json and composer.lock file exist in your workspace root or the phpcs.composerJsonPath in order to check for the composer dependency. If you wish to bypass this feature you can set the phpcs.executablePath configuration setting.

NOTE: You can also install phpcs on your system using pear or even manually but is beyond the scope of this plugin.

System-wide Installation

The phpcs linter can be installed globally using the Composer Dependency Manager for PHP.

Require phpcs package by typing the following in a terminal:

Project-wide Installation

The phpcs linter can be installed in your project using the Composer Dependency Manager for PHP.

Require phpcs package by typing the following at the root of your project in a terminal:

Plugin Installation

Basic Configuration

There 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 linting is enabled.

phpcs.executablePath

[ Scope: All | Optional | Type: string | Default: null ]

phpcs.standard

[ Scope: All | Optional | Type: string | Default: null ]

The following values are applicable:

You may set the default_standard used by phpcs using the following command:

or when using composer dependency manager from the root of your project issue the following command:

After you install the custom coding standard, you can make it available to phpcs by issuing the following command:

or when using composer dependency manager from the root of your project issue the following command:

The setting can be set to the absolute path to a custom coding standard:

or you can use the path to a custom ruleset:

The setting can be set to your workspace relative path to a custom coding standard:

or you can use the path to your project’s custom ruleset:

phpcs.autoConfigSearch

[ Scope: All | Optional | Type: boolean | Default: true ]

NOTE: This option does not apply for unsaved documents (in-memory).

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.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 ]

Advanced Configuration

phpcs.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 composer.json file.

Diagnosing common errors

The phpcs report contains invalid json

This 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:

NOTE: The ‘-q’ parameter is automatically passed on phpcs v.2.6.2 and above to suppress such errors. Please update phpcs to a version >=2.6.2.

Acknowledgements

The extension architecture is based off of the Language Server Node Example.

Additional inspiration comes from Atom Linter-phpcs.

Contributing and Licensing

The 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.

Источник

Php sniffer visual studio code

PHP CodeSniffer and WordPress Coding Standards with VS Code

Last Updated 2020-07-31 by @tommcfarlin

This 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.

php sniffer visual studio code. Смотреть фото php sniffer visual studio code. Смотреть картинку php sniffer visual studio code. Картинка про php sniffer visual studio code. Фото php sniffer visual studio code

All of the resources used in this guide are linked at the bottom. This guide is also licensed MIT. 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.

If you’re looking for corresponding blog posts, please see:

As always, don’t forget to checkout the CHANGELOG to track everything that’s changed since the initial release of this guide.

The following steps assume you have PHP installed and globally accessible on your system. You can test this by entering the following command in the terminal:

And you should see something like this:

If 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:

And you should see something similar to this:

That should give you enough information for the rest of this guide.

2. Installing Composer

Installing 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 or follow the quick steps below (which summarize the manual, anyway):

And now you can access Composer from anywhere in your system. To do try it out, enter the following command in your terminal:

You should see something like this:

With Composer globally installed, you can now install the WordPress Coding Standards rules.

3. Installing PHP CodeSniffer

For 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.

From the integrated terminal within Visual Studio Code, enter the following command:

4. Installing the WordPress Coding Standards Rules

I recommend placing the rules in a directory you can refer to often. Personally, I use a projects directory to manage all of my work.

This 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.

5. Tell PHPCS About WPCS

From within Visual Studio’s integrated terminal, make sure that you’re in your project’s directory and then issue the following command:

And this will tell your project’s copy of PHPCS where the WordPress Coding Standards are.

6. Update User Settings

Make sure the file looks like the following (though you may need to tweak based on your existing settings)

And 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.

About

How to install PHP CodeSniffer and the WordPress Coding Standard Rules in Visual Studio Code.

Источник

Php sniffer visual studio code

PHP Code Beautifier and Fixer for Visual Studio Code

This extension provides the PHP Code Beautifier and Fixer ( phpcbf ) command for Visual Studio Code.

phpcbf is the lesser known sibling of phpcs (PHP_CodeSniffer). phpcbf will try to fix and beautify your code according to a coding standard.

php sniffer visual studio code. Смотреть фото php sniffer visual studio code. Смотреть картинку php sniffer visual studio code. Картинка про php sniffer visual studio code. Фото php sniffer visual studio code

right mouse-click, in context menu, select ‘Format Document’. Here using the WordPress-Core standard. You can also enable formatting on save.

phpcbf must be installed. phpcbf is installed when you install phpcs.

I recommend phpcs version 3.2.2 or later.

A quick install is using composer. After installing composer, in your workspace root, run the following command:

composer require «squizlabs/php_codesniffer=*»

This extension has the following settings:

The default settings are

If you add a standard to phpcs, it will be available for phpcbf. Some popular standards are: Drupal, WordPress, Yii2, Magento and Symfony.

You can also point to a phpcs.xml rules file, eg: «phpcbf.standard»: «/file/path/phpcs.xml»

None, but this is my first vscode extension, you’re warned 🙂

I learned a lot reading the code of, and borrowing code from PHP CS Fixer for Visual Studio Code.

Copyright and License

PHP Code Beautifier and Fixer for Visual Studio Code is copyright 2018 Per Soderlind

PHP Code Beautifier and Fixer for Visual Studio Code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

PHP Code Beautifier and Fixer for Visual Studio Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the Extension. If not, see http://www.gnu.org/licenses/.

About

PHP Code Beautifier and Fixer for Visual Studio Code

Источник

Php sniffer visual studio code

Gamegos PHP Code Sniffer

Gamegos PHP Code Sniffer is a PHP code standard checker/beautifier/fixer tool based on PHP_CodeSniffer and includes custom sniffs used in PHP projects developed by Gamegos.

Gamegos PHP Code Sniffer requires PHP 5.3 or later.

Install via Composer

Binaries are located in bin directory but composer installer creates links under your vendor binary directory depending on your composer configuration.

Make sure the hook script is executable.

You can customize configuration by adding a file called phpcs.xml file into the root directory of your project. The phpcs.xml file has exactly the same format as a normal ruleset.xml file, so all the same options are available in it. You need to define Gamegos rule to import all the Gamegos rules.

Using a custom bootstrap file

You can add custom bootstap files to be included before beginning the run. Some sniffs need to load classes from your project; so adding a autoload file will allow sniffs to do this.

All PSR2 sniffs except Squiz.WhiteSpace.ControlStructureSpacing are imported by default.

This sniff has two rules and fixes.

You can test any modifications by running phpcs.php, phpcbf.php and phpcs-pre-commit.php scripts under scripts directory.

Run the command below to re-build binaries:

Current version is built on PHP_CodeSniffer 2.8.1 which is locked in composer.lock file. To import new versions; edit composer.json file if required and run composer update command, then commit the modified composer.lock file. Updating PHP_CodeSniffer version may break some of Gamegos sniffs, so you must carefully track any changes on PHP_CodeSniffer before updating.

[1] A class loader is required (eg. via a bootstrap file), otherwise a warning ( Internal.Gamegos.NeedClassLoader ) will be generated. You can override this rule in phpcs.xml file in your project to prevent warnings. ↩ ↩ ↩ ↩

PHP_CodeSniffer is licensed under the BSD 3-Clause license.

About

PHP code standard checker/beautifier/fixer tool based on PHP_CodeSniffer.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *