vscode-phpcs icon indicating copy to clipboard operation
vscode-phpcs copied to clipboard

Proper way to setup this?

Open ghost opened this issue 7 years ago • 26 comments

I am not sure what I am doing wrong but I can't get this plugin to work. I keep getting error messages:

image

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?

ghost avatar Feb 23 '18 02:02 ghost

@LittleHamster Did you try running

/usr/local/bin/phpcs --report=json -q --encoding=UTF-8 --standard=WordPress /path/to/your/php/file

ikappas avatar Feb 23 '18 09:02 ikappas

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

ghost avatar Feb 23 '18 22:02 ghost

@LittleHamster Can you check whether "phpcs.autoConfigSearch": "false" changes the error?

ikappas avatar Feb 26 '18 11:02 ikappas

@ikappas sadly no :( still the same error message

ghost avatar Feb 26 '18 22:02 ghost

@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 avatar Feb 27 '18 07:02 ikappas

@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

ghost avatar Mar 01 '18 01:03 ghost

@LittleHamster Are you on a Linux or Mac ? Also have you tried installing phpcs via composer globally?

ikappas avatar Mar 02 '18 18:03 ikappas

@ikappas I am on a Mac. yes, I tried to install phpcs via composer globally, but still no luch

ghost avatar Mar 03 '18 15:03 ghost

@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 avatar Mar 04 '18 15:03 sethstha

@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: image

here are my settings:

    .....
    "phpcs.standard": "WordPress",
    "phpcs.autoConfigSearch": false

ghost avatar Mar 05 '18 03:03 ghost

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. 1 2 3

kevinfiol avatar Mar 08 '18 15:03 kevinfiol

@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 . in your phpcs.xml which I have seen causing some trouble. Can you comment that out and check whether your situation changes?

ikappas avatar Mar 08 '18 16:03 ikappas

@kevinfiol You can also set phpcs.executablePath in workspace/project settings (not user) to "vendor/bin/phpcs"

ikappas avatar Mar 08 '18 16:03 ikappas

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.

5 4

kevinfiol avatar Mar 08 '18 17:03 kevinfiol

@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 )

ikappas avatar Mar 08 '18 18:03 ikappas

Yes. jewswb

kevinfiol avatar Mar 08 '18 20:03 kevinfiol

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 avatar Mar 08 '18 20:03 kevinfiol

@kevinfiol The latest version of the extension is 1.0.5

ikappas avatar Mar 08 '18 20:03 ikappas

@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 avatar Mar 08 '18 20:03 kevinfiol

@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 avatar Mar 08 '18 20:03 ikappas

@ikappas Sure, I will look into this more tomorrow. :) Thanks.

kevinfiol avatar Mar 08 '18 21:03 kevinfiol

@kevinfiol Thank you in advance 👍

ikappas avatar Mar 08 '18 21:03 ikappas

@kevinfiol Did you have a chance to debug?

ikappas avatar Mar 13 '18 13:03 ikappas

@ikappas Sorry, got swamped in work. I've attempted to debug, but keep hitting this issue immediately upon starting to debug:

rxqeto

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 avatar Mar 14 '18 17:03 kevinfiol

@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 avatar Mar 22 '18 15:03 ikappas

@ikappas any feedback about my issue, kevin hijacked my issue :( I am still having the issue

ghost avatar Apr 15 '18 13:04 ghost