-
-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WordPressCS 3.0: Fatal error: Cannot declare class WordPressCS\WordPress\Sniffs\Files\FileNameSniff #2375
Comments
@dawidurbanski I have cloned that repo and tried with both the I do see some other things which aren't as they should be in your repo, but that still shouldn't cause this issue. As a side-note, now WordPressCS 3.0 has been released, why would you still want to use Advise for improving your setup (also largely mentioned in the upgrade guide):
|
Thanks for the feedback @jrfnl!
I'm not using develop branch. I only added this to satisfy:
and
I cleaned the repo a bit, now using only Unfortunately I still see the issue.
The environment I test this on is Local by Flywheel, by using the "Open site shell" option. The thing is, it uses composer v 2.1.5:
This version does not have In theory before composer 2.2, it should allow all plugins by default, so I should not be required to run this Is it maybe the case that WPCS3.0 does not support Composer < 2.2? If that's the case I'm fine with that :) We may just update the docs to have that info. EDIT: and then I should move this to Local by Flywheel forums to push them to update the bundled composer version |
Also, I created this super short (1:45), full steps reproduction screencast to shed some more light: https://www.youtube.com/watch?v=XMzgDL9gS3U Summary:
|
Aside from the plugin needing permission in Composer >= 2.2, there is nothing Composer specific and the plugin itself supports both Composer 1.x as well as 2.x, so Composer 2.1.5 is supported. Having said that, I tested with Composer 2.1.5 just to be sure and again couldn't reproduce the issue. I don't have Local by Flywheel installed, so can't test with that, but other than that, I have replicated your complete setup with Composer 2.1.5, PHP 8.1.9 and cannot reproduce the issue. I'd like to suggest you try on your native OS and if things work correctly there, then I suggest you report this to Local by Flywheel as that would then be the "variable" which is causing the problem. |
Thanks! I appreciate your help. I consider this to be solved then. |
It's a case-sensitivity issue. I was able to reproduce locally (using LocalWP), but couldn't reproduce when excluding I then noticed that the sniff file name is called Once I fixed it, I got no error. I was then able to try excluding
With
So, by using the wrong case for the exclusion, you're actually trying to (first) include the sniff, before later excluding it for the |
@GaryJones WooHoo! That was it! In case someone lands here from Google, I you took this from the phpcs.xml.dist.sample from the "using custom ruleset" part of the docs. @GaryJones @jrfnl I created PR to fix this: Thanks again for all your help. I appreciate it a lot. |
Oh cricky... that explains it! Thanks for figuring this out @GaryJones and thanks @dawidurbanski for the PR to fix the sample ruleset! As a rule of thumb, arguments on the CLI are treated case-insensitively in PHPCS (well, mostly, not completely), while rulesets are treated case-sensitively. However, this is not a straight-forward problem to solve as the autoloader still needs to find the file if it's the first mention in a ruleset and for case-sensitive file systems (*nix, Mac), that means it needs the correct case. @GaryJones @dingo-d Should we maybe add a task to the CI to do a minimal test run with the sample ruleset (which is allowed to fail ?) to prevent this kind of typo (re-)entering the example ruleset in the future ? |
@GaryJones I've been trying to set up a test case for PHPCS itself for this (with the intention to at least make a second include for the same sniff using a different case less error prone), but as I'm on Windows, I'm struggling to create a working test case. Could you share the |
Bug Description
Minimal Code Snippet
I created a repository with minimal reproduction.
You can test this using
develop
branch using use-develop branch on the repro repository.Error Code
Custom Ruleset
Environment
Tested Against
develop
Branch?develop
branch of WordPressCS.The text was updated successfully, but these errors were encountered: