Open alexd73 opened 5 years ago
I tried same setup and the current result is a less verbose error, "phpcs: Cannot read property 'toString' of null"
The closest I could get was to create an executable bash wrapper at /usr/local/bin/phpcs
with the following:
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
docker run --rm --user $(id -u):$(id -g) --volume $(pwd):/project herloct/phpcs --standard=PSR2 $@
Then I'm able to run phpcs from the VSCode terminal. I still can't get the GUI to recognize issues, however. I see the spinning loading icon that phpcs is attempting to parse the current PHP file as I edit it.
OS: Ubuntu 19.04 Docker version 19.03.0-beta5, build 4a18bf4
I do the same thing with phpcbf (create a executable bash wrapper at /usr/local/bin/phpcbf
with the following content):
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
docker run --rm --user $(id -u):$(id -g) --volume $(pwd):/project herloct/phpcbf --no-patch $@
I almost managed to make it work.
I managed to get my phpcs binary recognized by disabling pseudo-tty allocation on docker-compose exec with -T
flag.
My wrapper looks like this:
#!/bin/sh
docker-compose exec -T php phpcs "$@"
But then the only output I got was a warning that the file doesn't contain php code.
Seems like the extension builds the following command to lint a file:
bin/phpcs --report=json -q --encoding=UTF-8 --standard=PSR12 --error-severity=5 --warning-severity=5 --stdin-path=your-php-file -
Where your-php-file is the absolute path to your file.
Thus passing the absolute path to --stdin-path cannot work work since this path does not exists in the container.
I don't know if this can be fixed.
At first I was having the same problem as jgonyea where phpcs just spins infinitely, but I finally got it working. The key was adding the -i
flag. Here's the script that works for me:
#!/bin/bash
# note: pwd will be set to the directory that you opened vscode from
docker run -i --rm -v $(pwd):$(pwd) cytopia/phpcs $*
I also get "phpcs: Cannot read property 'toString' of null" using @benharris-conversica approach Also from the extension's trace I can't figure out what's the problem =/
I have a similar issue, where I'd like to use a version of phpcs
that is located inside a container that is normally running for my project.
I have created a bash wrapper:
#!/bin/sh
docker exec -it -w '/var/www/html/' [CONTAINER ID] bash -c 'phpcs'
Running this script directly provides the response I expect:
$ ./phpcs.bash
ERROR: You must supply at least one file or directory to process.
Run "phpcs --help" for usage information
When I try to set the executable path to this in VSCode, I get the error: "phpcs: Unable to locate phpcs. Command failed: "[/path/to]/phpcs.bash" --version the input device is not a TTY"
"phpcs.executablePath": "[/path/to]/phpcs.bash",
Is there any way to get this to work?
-mike
Not sure how your script worked, benharris-conversica , but I adjusted the internal mount point to /data as on that particular docker image page and that works nicely for me.
#!/bin/bash
# note: pwd will be set to the directory that you opened vscode from
docker run -i --rm -v $(pwd):/data cytopia/phpcs $*
My current version of the script looks similar, I must have switched the mount to /data at some point as well:
#!/bin/bash
# see: https://github.com/cytopia/docker-phpcs and https://hub.docker.com/r/cytopia/phpcs
PHPCS_IMAGE=cytopia/phpcs:latest-php7.3
PHPCS_STANDARD=./phpcs.xml
PHPCS_IGNORE_DIRS=tests,vendor
docker run --rm \
--volume $(pwd):/data \
$PHPCS_IMAGE \
-p -s \
--standard=$PHPCS_STANDARD \
--ignore=$PHPCS_IGNORE_DIRS \
--runtime-set ignore_warnings_on_exit 1 \
--extensions=php \
$*
I use wodby/drupal-php (docker4drupal), which have inside a phpcs
docker-compose exec php phpcs --version
Can I use this in vscode?
I trying create exec file phpcs-vscobe
and have an error from phpcs-vscode:
I added to file
export COMPOSE_INTERACTIVE_NO_CLI=1
and error changed to
I don`t known that I can try else. I whuld be happy if we could solve this situation. :)