Support project's local phpcs installation#666
Conversation
w0rp
left a comment
There was a problem hiding this comment.
Good idea.
Could you cover this with some tests? There are a few tests which have some blank files in some directories inside of the test directory and set the filename for the buffer so it picks up on local executables. You might have to run chmod ug+x for the dummy executable files.
| \ : '' | ||
|
|
||
| return 'phpcs -s --report=emacs --stdin-path=%s ' . l:standard_option | ||
| return ale_linters#php#phpcs#GetExecutable(a:buffer) |
There was a problem hiding this comment.
You should ale#Escape the executable here, as the path might contain spaces, etc.
| \ a:buffer, | ||
| \ 'vendor/bin/phpcs', | ||
| \ 'phpcs' | ||
| \) |
There was a problem hiding this comment.
Could you make the global executable configurable and add a use_global option while you're at it, similar to eslint and others?
|
Thanks for the feedback! It's my first time writing any vimscript (outside of vimrc); I'll try to address your concerns and update the pull shortly. |
w0rp
left a comment
There was a problem hiding this comment.
Nicely done. Looks good to me. 👍 I might see if new can be replaced with file in the tests.
| call ale#Set('php_phpcs_use_global', 0) | ||
|
|
||
| function! ale_linters#php#phpcs#GetExecutable(buffer) abort | ||
| return ale#node#FindExecutable(a:buffer, 'php_phpcs', [ |
There was a problem hiding this comment.
You fell into the "pit of success" here. I might rename this because it turns out it works for more than just node programs.
|
I'm using root/sage (8.5.1 latest production release) which is a WP theme. This reason this is important is because I also have template overrides. The template overrides are done with WP Coding Standards that way diffs can be checked against the originals when needed, and the rest of the theme follows the Roots guidelines (PSR-2 with slight modifications). I have PHPCS scripts for both of them. What is the best way to handle linting for this situation? (btw just switched to ale from neomake and loving the performance boost so far) |
|
PHPCS should pick up a |
|
Yes but what if the project has two different set of styles? For example the main dir all subdirectories follow a variant of PSR-2 except for files in |
|
Based on this page, it looks like PHPCS may pick up on directory-relative ruleset files. Failing that, there appears to be at least some support for specifying included/excluded files to lint in the phpcs.xml file, although it's not clear to me from their docs if you could set up two configurations "next to each other" in that way. You might be able to rig something up with an |
This change allows use of the PHPCS linter when installed as a project's dev dependency, instead of only a global install. It firsts checks for
vendor/bin/phpcsas the executable path before falling back to the previous behavior (phpcsanywhere on the $PATH). This is similar to how many Node-based linters work, but with the paths from PHP's Composer.