Closed AlchemyUnited closed 12 months ago
Hi @AlchemyUnited!
In the Readme you can see how to use WordPressCS. wpcs
is not a command that is used.
# Project local install
vendor/bin/phpcs -ps . --standard=WordPress
# Global install
%USER_DIRECTORY%/Composer/vendor/bin/phpcs -ps . --standard=WordPress
You can create composer scripts to create a wpcs
command you'd run on your command line as composer wpcs
.
Hope this helps.
@dingo-d - not a command? Ok. Great to know. But then how do I test if it's working or not? And furthermore, how do I carry that on to Visual Studio code.
My bone to pick is..."If all went well..." But there's nothing about "If All didn't go well..." Cause for me, all isn't going well for whatever reason. So addressing some possible troubleshooting issues does make sense, yes?
@dingo-d - it's running from the command line. It might help to mention somewhere that this:
Universal.Arrays.DisallowShortArraySyntax.Found
e.g. short array syntax is not allowed (Universal.Arrays.DisallowShortArraySyntax.Found)
is actually wpcs working. I'm also seeing this in Visual Studio code. So that much seem ok. Good. Great!!
However, I'm also being told in to use spaces not tabs for indenting. I thought - perhaps I'm mistaken - wpcs expects tabs.
So there's some progress, I think.
Thanks for your help.
However, I'm also being told in to use spaces not tabs for indenting. I thought - perhaps I'm mistaken - wpcs expects tabs.
It does. Please check whether your project contains a [.]phpcs.xml[.dist]
file. That file can include standards and then overrule certain settings, which may be what is happening here.
In the Wiki you can find links on how to set things up correctly with various IDEs.
hey @jrfnl - To clarify, I'm installing phpcs and wpcs as global.
That said, I don't have a phpcs .xml or .xmldist in the project*. I should also add, this was fine a couple of weeks ago. Then VSC started saying "wpcs can't be found." I believe that starter when I (finally) upgraded from Composer 1. to 2.* but maybe that was a coninscidence?
**The Spatie Ray plugin does have phpcs.xml, but that's not in the project root. Even so, I've renamed it and restarted VCS and I'm still gettig "use spaces". I'm also getting a error "opening brace should be on a new line". If I remove the space between the ) and { then I get two errors. One about putting the brace on the next line, but then also, wpcs saying there should be a space between the ) and the {
So wpcs is working and phpcs is working. But something is causing a couple of the WP rules to not work. Yeah. I agree. Weird. But that's what I'm seeing.
And yes, I've followed that guide for VSC. Unfortunately, I'm not familiar with the underlying technology enough to try to trouble shoots why wpcs and phpcs are working but not consistently (e.g., the spaces not tabs, the bit with the opening brace).
Any other clues / suggestions about what I should try in terms of trouble shootting?
@AlchemyUnited Well, there's a couple of things which come to mind:
--standard=WordPress
still advise to use spaces ? and braces on the next line ?
If so, please run phpcs --config-show
and share your outcome.which phpcs
, on Windows where phpcs
and share your outcome.If both of the above are set correctly, then the problem is the VCS configuration, which you might be better off getting help with on a VCS related forum.
For VSC, compare your setup to https://artiss.blog/2023/09/how-to-add-phpcs-checking-to-visual-studio-code/
Grrrr. It looks like one of the other extensions I had installed and activated was the problem.
I apoligize for all this confusion.
But in my defense, it's the same set of extensions I've been using for a while now. An update recently must have triggered it.
Bug Description
I''ve using Composer and can see the package is installed.
Minimal Code Snippet
The issue happens when running this command:
... over a file containing this code: n/a
Environment
Ulimately, I want to use phpcs and wpcs in VSC but when that didn't work I went for KISS and just trying to get it to work via CL.
Additional Context (optional)
1) Local OS: Win 10 Pro 2) I've had phpcs + wpcs working in the past. But recently VSC was giving me a msg, something like "wpcs not found" which caused me to revist.
3) I also recently (finally) upgraded to Composer 2. 4) Best I can tell phpcs is working via CL and in VSC 5) But wpcs even tho it's in the vendor folder is not recognized 6) I also noticed that Composer is not* install wpcs's require dev packages. Shouldn't it?
I'm at a loss TBH.
fwiw I'm in the middle of troubleshoot a similar problem with PHPCompatibility. That installs but doesn't sniff properly. And I've tried to add the WP specific package and while it installs I can't get it to be recognized either.
Again, I'm at a loss. But I'm burning up time and energy and getting no where. Even ChatGPT couldn't help.
Thanks.
Tested Against
develop
Branch?