-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
PHPCS 3.0.0 compatibility. #718
Comments
The namespace requirement means we'll need to drop support for PHP 5.2. I'm not heartbroken by that, but Travis builds on PHP 5.2 will need to skip running PHPCS. |
It seems they have a minimum requirement as PHP 5.4. Do we know when 3.0 is planned to be released? |
I'd be cautious of upping the minimum PHPCS to 3.0 for now as other standard libraries - for example PHPCompatibility - which may be used in conjunction with this one may not be compatible with it (yet) and this could cause issues. Might it be an idea to create a separate PHPCS 3.0 branch (similar to how PHPCS itself is currently doing it) instead for now ?
AFAIK there is no public release planning for the new version, so probably "when it's ready" |
That sounds like work. 😄 I'd say wait until 3.0 is actually released, and then plan to be compatible with it in our next release after that. Anybody who needs to use sniffs that aren't compatible with PHPCS 3.0 yet can just use an older version of WPCS for a bit. We can back-port more bugfixes if we want to, but I don't fancy juggling two branches and backporting all new features. If it is worth it to particular folks, of course, they are welcome to do so, but I have a feeling it would just get tedious after a while. |
I think the consensus is that yes, we want it, but adding it in before 3.0 is released, is not desired. PHPCS 3.0 RC2 has been tagged, so it won't be long. |
I'm running phpcs inside docker container, so I need new Is there any action plan regarding phpcs 3.0 support? thanks. |
@sandrodz As stated above: once PHPCS 3.0 has been released, i.e. is no longer in alpha/beta/RC. |
FYI: PHPCS 3.0 has just been released. https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.0.0 |
PHPCS 3.0.0 broke WPCS on the core-media-widgets plugin. See xwp/wp-dev-lib#234 |
As I understand it, in order to be compatible with 3.0.0, the changes necessary would be so great that we'd no longer be compatible with 2.*, am I right? It doesn't really matter to me, but I just want to be clear about it. I suggest that we release 0.12.0, and then make 0.13.0 the release that just updates to be compatible with 3.0, not really adding any other features. The update to 3.0 will break most open PRs, so ideally we would try to get them merged into 0.12.0, I guess. Does anybody else have thoughts? |
Generally speaking: yes. However.... for the PHPCompatibility standard we're going to attempt to make the standard compatible with both PHPCS 2.x as well as PHPCS 3.x. See PHPCompatibility/PHPCompatibility#367 The reason - at least for PHPCompatibility - to try and be compatible with both, is that it is often used on servers where the users does not have the rights to upgrade the PHPCS install. As for WPCS, if it is possible and not too hard to do, it would be good to have dual PHPCS compatibility for at least the next six months or so, as it can be a lot of work to upgrade a custom standard, so people who use WPCS combined with other custom standards, may not be able to upgrade to PHPCS 3.x yet and would run into issues using two standards with different requirements.
👍 It would be nice if #826, #840, #858 and possibly #843 could be coached to be ready for merge so these could still go in that release, though the current state of 0.12.0 is quite feature rich/ready for release already.
That would depend on whether the dual compatibility would be possible/considered for WPCS. If it is, current PRs should probably still be fine with only some minor adjustments. |
Is there a reason not to do a major version update as it is breaking change? e.g. version |
There is general agreement that 1.0.0 should denote that WPCS is feature complete as regards WordPress's core coding standards. See #519 (comment). I don't think that we are there yet, although I did have a similar thought about a potential 1.0 here. |
Maybe it is time to revisit that discussion ? Looking at the annotated WP Core ruleset, we currently cover ~90% and some of the remaining things can not easily be covered by static analysis tools. |
OK, I'd be in favor of that. I had considered the possibility of a shim, but wasn't sure if it was possible/worth it. If you believe that it is, then by all means lets give it a try. If what is needed is mostly a shim, then couldn't it be developed separately from any one standard, and then people that needed it could use it with WPCS or custom standards or whatever they needed to use it with? Although I gather that some things might not be possible just via a shim, so WPCS might still need to be updated to be compatible with the shim. Anyway, I guess that for right now WPCS will just wait to see what is possible in that regard, and then make a decision as to what to support and how long. In the mean time we can try to get some of those PRs merged. |
Correct. WPCS would still need to be updated, the precise details I can't yet tell you, but I expect they will be along the lines of:
More info will be available once I've had time to attempt this for PHPCompatibility. |
I've started looking into this and while I think I can get it working, I would suggest waiting a bit as I've already found numerous bugs in the 3.0/3.0.1 release which should be fixed (merged) first as they will probably impact users of WPCS as well. Edit:And another one which is a prerequisite for getting cross-version compat working: Edit:And one more: squizlabs/PHP_CodeSniffer#1453 In other words: solutions to all four issues will need to be merged upstream and we need to wait for an upstream release containing these fixes before we can release a PHPCS 3.x compatible version. |
Short update about my current line of thinking.
That way, while using the @WordPress-Coding-Standards/wpcs-collaborators Please leave an opinion 👍 / 👎 about this. |
I need some help. Bright ideas welcome. We currently extend the upstream We overload one method in the WPCS version: In PHPCS 2.x the function declaration of the method we overload is: public function processMultiLineArray(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $arrayStart, $arrayEnd) {} In PHPCS 3.x the type hint for the If I use a typehint (aliased or not), PHPCS 3.x will throw a Anyone has any bright ideas how to get round this ? If worse comes to worst, we'll need to uncouple from the upstream sniff and have one or more WPCS native sniffs for the few things which are still left over in the sniff:
|
The idea that I came up with is to create two different sniffs for each version. It would require loading a specific class depending on the version. I have not tested this. Don't worry about telling me I am wrong. class WordPress_Sniffs_Arrays_ArrayDeclarationSniff extends Squiz_Sniffs_Arrays_ArrayDeclarationSniff {
public function newProcessMultiLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd ) {
// ... all of the code ...
}
}
class WordPress_Sniffs_Arrays_ArrayDeclaration29Sniff extends WordPress_Sniffs_Arrays_ArrayDeclarationSniff {
public function processMultiLineArray( PHP_CodeSniffer_File $phpcsFile, $stackPtr, $arrayStart, $arrayEnd ) {
$this->newProcessMultiLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd );
}
}
class WordPress_Sniffs_Arrays_ArrayDeclaration30Sniff extends WordPress_Sniffs_Arrays_ArrayDeclarationSniff {
public function processMultiLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd ) {
$this->newProcessMultiLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd );
}
} |
@grappler Thanks for taking the time to think about this. Unfortunately I don't think this will get us to a solution. We cannot have one ruleset for PHPCS 2.x and another for PHPCS 3.x, so that means that both sniffs would have to be included in the So that still doesn't get us round the problem, which is that PHP will throw the warning when it reads in the class - not when the function is called. As all three classes would always be loaded, that means we'd still have one or the other throw the |
Without looking through the code my quick guess would be that one way or another this will error out if sticking with inheritance/overloading. Not sure without trying if composition makes sense? Use upstream class internally within WPCS class, without subclassing? |
@Rarst Thanks you too for helping me think of other solution directions. Just to make sure I understand you correctly, you mean doing something like this ? class WPCS_Class implements Sniff {
protected $upstream;
protected function get_upstream_object() {
$this->upstream = new Squiz_Class();
// Use the object here or in other methods.
}
} The upstream class has four methods:
So having said that, in effect, it would only be the 4 checks in So I think in that case, it would make more sense having one or more WPCS native sniffs to sort this out. |
Using only 9, out of the 26 upstream errors, would suggest the WPCS native sniffs would be the way to go here. Wild idea: Could we change the PHP error reporting level to remove |
Don’t mess with error level, it’s not worth it and is major code smell. |
@GaryJones I like the wickedness of the idea, unfortunately that would not help us. |
Status update:
Upcoming:Things which will need to be addressed before PHPCS 3.x compatibility can succeed;
PHPCS 3.x compatibility:
|
Status Update:
Once #1042 and #1044 are merged, I'll pull the third prep PR. Technical notes:The problem with the PHPCS 2.x unit tests was that the PHPCS 2.x unit test suite can not deal with namespaced unit test classes, which is a requirement for PHPCS 3.x. The way I've solved this now is a bit hacky:
This also means that the commands to run the unit tests will not be the same for PHPCS 2.x / 3.x while we still support both. I will update the Creative ideas for alternative solutions to this are welcome and who knows we might find a more elegant way, but I can't think of any at this moment. Just glad that I (finally) got the last bit working 😎 |
Thanks. #1045 is the next one. |
#1045 is merged. |
Thanks. Rebasing & tidying up the main PR now. This may take a little while. |
Rewriting history: should or shouldn't N.B. |
What I do sometimes in refactoring like this: Before:
After:
I think that preserving the history while also noting when the sniff itself was originally introduced is helpful. This means that you can also keep the other |
@JDGrimes I'm not sure we're talking about the same thing here...? I meant more, what to do about comments like:
Should this be changed to the below ?
As all the class names have been changed, a lot of comments still refer to the old classnames. Should those be updated or not ? A secondary question would be: should all classes get a |
No - leave as the original
I'd initially say No, but https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#717-since suggests otherwise. |
Which is why I am in two minds about it. It just feels a bit redundant adding the same comment in every single class (118 x). |
No.
I'd say yes. I mean, it is technically a different class, because it has a different FQCN. The PHPDoc is not for the sniff, it is for the class itself. So it should document the version that the FQCN was introduced. It is redundant now, but in the future as new sniffs are introduced anybody will be able to see at a glance which classes were namespaced from the start and which were not. This is what I was answering above, I should have read your question more closely. 😄 |
The new version of PHP CodeSniffer has some nice features, but introduces breaking changes which mean that the WordPress coding standards are not compatible.
I had a quick look, and I think the minimum required is to namespace the WPCS codebase and import dependencies to ensure everything is autoloaded.
For reference:
The text was updated successfully, but these errors were encountered: