vscode-phpcs
vscode-phpcs copied to clipboard
Proper way to setup this?
I am not sure what I am doing wrong but I can't get this plugin to work. I keep getting error messages:
I have setup PHPCS with PhpStorm and it works perfectly but I can't get it working for VSCODE with this plugin. I followed all the instructions,
php -v
PHP 7.1.7 (cli) (built: Jul 15 2017 18:08:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
reinstalled PHPCS with pear
downloading PHP_CodeSniffer-3.2.3.tgz ...
Starting to download PHP_CodeSniffer-3.2.3.tgz (560,524 bytes)
.................................................................................................................done: 560,524 bytes
install ok: channel://pear.php.net/PHP_CodeSniffer-3.2.3
but nothing. I can't get this to work, any idea what is happening?
@LittleHamster Did you try running
/usr/local/bin/phpcs --report=json -q --encoding=UTF-8 --standard=WordPress /path/to/your/php/file
@ikappas thanks for your response, this is the output of your command:
sh: line 1: 1684 Illegal instruction: 4 stty size 2>&1
ERROR: option "-1" not known
Run "phpcs --help" for usage information
so if I remove -1
I get a message like:
{"totals":{"errors":119,"warnings":48,"fixable":93},"file...
@LittleHamster Can you check whether "phpcs.autoConfigSearch": "false" changes the error?
@ikappas sadly no :( still the same error message
@LittleHamster The unknown error is thrown when PHP_CodeSniffer returns an error in stderr and is not one of PHP error or exception. That means that the command to execute phpcs fails for some reason.
Some users have reported that you need to upgrade your php to >=7.1.13 or >=7.2.1 to avoid bug introduced by earlier versions of php in 7.1.x || 7.2.x.
@ikappas so I updated the php
php -v
PHP 7.2.2 (cli) (built: Feb 1 2018 13:23:34) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.2, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
Dolatabadi@connected ~ $
but still have the same issue PHP_CodeSniffer works on PhpStorm so not sure why it doesnt work here
@LittleHamster Are you on a Linux or Mac ? Also have you tried installing phpcs via composer globally?
@ikappas I am on a Mac. yes, I tried to install phpcs via composer globally, but still no luch
@LittleHamster I had the same issue and couldn't get phpcs to work. I will give you clear instruction here.
First, open the project on vscode and open inbuilt terminal.
Install phpcs
composer require squizlabs/php_codesniffer
Install wpcs
composer require wp-coding-standards/wpcs
This plugin will automatically load phpcs standards found
composer require dealerdirect/phpcodesniffer-composer-installer
Now try checking if phpcs standards are installed or not by typing
vendor/bin/phpcs -i
If standards are showing and still you cannot get it to work, try linting a file through command using --standard="WordPress"
and if it throws some error delete your phpcs installed locally and globally. And follow the above instruction again.
@sethstha I followed your instructions and for this command I get the following output:
vendor/bin/phpcs -i
sh: line 1: 40564 Illegal instruction: 4 stty size 2>&1
The installed coding standards are PEAR, Zend, PSR2, MySource, Squiz, PSR1, WordPress-VIP, WordPress, WordPress-Extra, WordPress-Docs and WordPress-Core
but I still get this error:
here are my settings:
.....
"phpcs.standard": "WordPress",
"phpcs.autoConfigSearch": false
This extension has just straight up stopped working for me. Even tried using a global installation of phpcs. No more codesniffing for me it seems. I'm using a local Composer installation, located in /vendor/.
Here are some screenshots.
@kevinfiol On first screenshot you are viewing the output of PHP Intellisense... vscode-phpcs has it own output under PHP Code Sniffer when phpcs.trace.server is enabled. You can also use "phpcs.xml" in your phpcs.standard which is relative to project root. Last thing I noticed you are using the
@kevinfiol You can also set phpcs.executablePath in workspace/project settings (not user) to "vendor/bin/phpcs"
No change on my end. I tried using vendor/bin/phpcs
and vendor/bin/phpcs.bat
. No luck with either. I also do not see any option for PHP Code Sniffer in my Output panel.
@kevinfiol is the php executable C:\bin\easy\eds-binaries\php\php713v.... registered in you Windows PATH in your environment variables under System Advanced Preferences (see https://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10 )
Yes.
Update: I've since installed version 1.0.3 of the extension (as that was the last version wherein i did not have problems) and it is working again.
@kevinfiol The latest version of the extension is 1.0.5
@ikappas I realize this. It was not working while I was on 1.0.5. So I reverted back to 1.0.3, and it is working now.
@kevinfiol I realized what you did after posting :) Do you think you can clone the repo and debug this issue in windows so you can help me get some insight on this?
@ikappas Sure, I will look into this more tomorrow. :) Thanks.
@kevinfiol Thank you in advance 👍
@kevinfiol Did you have a chance to debug?
@ikappas Sorry, got swamped in work. I've attempted to debug, but keep hitting this issue immediately upon starting to debug:
I've replicated my environment at my home PC (using the plugin version 1.0.5), and found that the plugin works fine!! We do have some funky firewalls and other anti-malware measures here at work, so I imagine the issue might lay there, but I am unsure at this point.
@kevinfiol Sorry for the late response but this is not a firewall issue. There is a 10 sec timeout from task launch within which you need to open a php file to trigger the loading of plugin. If you run into this msgbox again you can ignore it and launch a second debug session with 'Attach to Server' task - provided you have the Extension Host running with an opened a php file first.
@ikappas any feedback about my issue, kevin hijacked my issue :( I am still having the issue