Uses PHP_CodeSniffer to format and lint PHP code.
- Runs
phpcs
to lint PHP code. - Runs
phpcbf
to format fixable PHP code validation errors.
This extension contributes the following settings:
phpSniffer.run
: When to runphpcs
(the linter). Can beonSave
oronType
.phpSniffer.onTypeDelay
: WhenphpSniffer.run
isonType
, this sets the amount of milliseconds the validator will wait after typing has stopped before it will run. The validator will also cancel an older run if the run is on the same file.phpSniffer.executablesFolder
: The folder where bothphpcs
andphpcbf
executables are. Use this to specify a different executable if it is not in your globalPATH
, such as when usingPHP_Codesniffer
as a project-scoped dependency. Include a trailing slash. Can be absolute or relative to the first folder in the workspace.phpSniffer.standard
: The standards to check against. This is passed to thephpcbf
andphpcs
executables as the value for--standard
. Can be absolute or relative to the first folder in the workspace.phpSniffer.snippetExcludeSniffs
: Sniffs to exclude when formatting a code snippet (such as when formatting on paste or on the commandformat on selection
). This is passed to thephpcbf
command as the value for--exclude
when not formatting a whole file.phpSniffer.windowsHardkill
: Windows only. Enables a toughphp
process killing for Windows machines. See Windows Hanging PHP Process below for details.phpSniffer.windowsPhpCli
: Windows only. RequiresphpSniffer.windowsHardkill
to betrue
. The name of thephp
executable thatphpcs
/phpcbf
runs with so that this extension can hard-kill it. See Windows Hanging PHP Process below for details.
When phpcs
encounters a malformed array declaration, it can sometimes hang from an error.
This is exacerbated by the fact that we do not have access to the spawned php
process in the extension code and cannot kill php.exe
directly.
This extension thus searches for the process by name in
phpSniffer.windowsPhpCli
to kill it. Since just matching by this name could
kill other non-related processes, the extension limits by CPU TIME
of between
2s and 10s.