Skip to content
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

Deprecate Remaining VIP sniffs #1410

Merged

Conversation

tomjn
Copy link
Contributor

@tomjn tomjn commented Jul 3, 2018

To the Files category, and deprecates the old sniff with a warning.

If this PR goes well I hope to do the same to all the other sniffs mentioned in #1409

@jrfnl
Copy link
Member

jrfnl commented Jul 3, 2018

@tomjn Glad to see the first PR for this.

This sniff in my opinion should not be moved, only deprecated. File system writes being forbidden is a VIP specific requirement which does not easily apply to other projects in the WP ecosphere, so this sniff is a candidate for complete removal in 2.0.0.

@tomjn
Copy link
Contributor Author

tomjn commented Jul 3, 2018

Ah, my goal with this PR is mostly to get to grips with the deprecation process for a sniff. This is certainly an issue for VIP, I can't comment on other hosting platforms, but this usually pops up in any situation were the uploads folder doesn't exist on the file system, which is why VIP flags it. But ignoring that, I just want to make sure I'm not making a colossal mess in follow up PRs, so consider this a practice run :)

@jrfnl
Copy link
Member

jrfnl commented Jul 3, 2018

I can't comment on other hosting platforms

The WPCS ruleset is not for specific hosting platforms. Other hosters can - just like Automattic - create their own PHPCS standard based on WPCS and add additional sniffs to it to facilitate their needs.

consider this a practice run

👍

@tomjn
Copy link
Contributor Author

tomjn commented Jul 4, 2018

yay travis is happy 🎉

@jrfnl
Copy link
Member

jrfnl commented Jul 5, 2018

@tomjn Do you mean that this PR is ready for review from your point of view ?

@tomjn
Copy link
Contributor Author

tomjn commented Jul 5, 2018 via email

@tomjn
Copy link
Contributor Author

tomjn commented Jul 6, 2018

@jrfnl the PR's ready for review, if all is good I'll do the same to the other sniffs mentioned in #1409

jrfnl
jrfnl previously requested changes Jul 6, 2018
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tomjn, the PR as it is now, is definitely in line with what has been discussed previously 👍

I've left a couple of remarks in line.

On top of that, there are two more things I'd like to discuss/remark:

  1. IMO it would be good to do the complete VIP deprecation in one go, in the same version of WPCS.
    Looking at your own time schedule - will you be ready with all the PRs in the next few days/ by the middle of next week ? If so, then this can go into 1.0.0.
    If not or if you are unsure, targeting 1.1.0 might make more sense (to be released as soon as all PRs regarding the deprecation of VIP are ready & merged).
    In that case, the version number used in @since and @deprecated tags should be adjusted.
  2. I'm not sure I see the value in having 7 commits for this - relatively small - change. Is there a pertinent reason not to squash them into one ?

);

/**
* Don't use.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a better description. The sniff is still active, just deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this is mostly due to copy paste from another deprecated VIP sniff

/**
* Don't use.
*
* @deprecated 1.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect a @since 1.0.0 Added to allow for throwing the deprecation notices. tag here instead.

The method itself is not deprecated, the sniff is.

In that respect, I'm missing a @deprecated tag in the class docblock.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 will change

*
* @return void|int
*/
public function process_token( $stackPtr ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other sniffs which have getGroups() and process_token() function declarations, the getGroups() method normally goes first, the process_token() method comes after it.
This is in line with the order in which the functions are called - getGroups() is called from within the register() method -, as well as the order used in the abstract sniff which this sniff extends.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

</rule>

<!-- Prevent duplicate messages from deprecated sniff. -->
<rule ref="WordPress.VIP.FileSystemWritesDisallow">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would disable the sniff completely in contrast to deprecating it. I think this block should be removed.

@tomjn tomjn force-pushed the vip-migrate-filesystem-write-disallow-sniff branch 2 times, most recently from cc96a0d to 5fb6bb5 Compare July 6, 2018 19:37
@jrfnl
Copy link
Member

jrfnl commented Jul 6, 2018

@tomjn Just scanned through the latest update related to the FileSystemWrites sniff and - except for missing a @deprecated tag in the class docblock [Edit: appears my file view was out of date, it's showing now 👍 ] -, all seems good now.

/**
* This sniff is active, but it's deprecated, handle the deprecation notices
*
* @deprecated 1.0.0 Added to allow for throwing the deprecation notices.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deprecated => @since

@jrfnl
Copy link
Member

jrfnl commented Jul 6, 2018

@tomjn I can see you are updating the PR with further changes. Could you please ping me when you are ready for the next review ?

@jrfnl jrfnl dismissed their stale review July 6, 2018 19:48

Requested changes were made. Not approving yet as more commits are still being added to this PR.

@tomjn tomjn force-pushed the vip-migrate-filesystem-write-disallow-sniff branch from 5fb6bb5 to 79170a3 Compare July 6, 2018 21:02
@tomjn
Copy link
Contributor Author

tomjn commented Jul 7, 2018

@jrfnl So I believe I'm ready for review, my main concern though is I'm unsure why the one travis check is failing :/ Any help appreciated

@tomjn tomjn changed the title Migrates the VIP Filesystem writes disallow sniff Deprecate Remaining VIP sniffs Jul 7, 2018
@GaryJones
Copy link
Member

my main concern though is I'm unsure why the one travis check is failing :/ Any help appreciated

The report says:

ERROR: Referenced sniff "WordPress.VIP.AdminBarRemovalSniff.DeprecatedSniff" does not exist

@jrfnl
Copy link
Member

jrfnl commented Jul 7, 2018

WordPress.VIP.AdminBarRemovalSniff.DeprecatedSniff

Should be: WordPress.VIP.AdminBarRemoval.DeprecatedSniff

👉 Once you fix this one, you'll start getting the same error for most of the others. When referencing sniffs in a ruleset, you need to leave out the Sniff at the end of the sniff name.

@tomjn tomjn force-pushed the vip-migrate-filesystem-write-disallow-sniff branch from f5d83d8 to e62e6cc Compare July 8, 2018 00:11
@tomjn
Copy link
Contributor Author

tomjn commented Jul 8, 2018

Gah such an obvious mistake, fixed

@jrfnl
Copy link
Member

jrfnl commented Jul 8, 2018

@tomjn The build still isn't passing. I suspect this is because of trailing whitespace within the touched XML file.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomjn Ok, I've reviewed the changes and left most feedback inline.

  1. As the AbstractVariableRestrictionsSniff is now no longer used by any non-deprecated sniffs, I would like to suggest to deprecated the abstract class as well.

    No warnings need to be thrown for that, it only needs an annotated @deprecated tag in the class docblock.

  2. Looks like the Sniff::has_html_open_tag() method from the Sniff class is only used by the now deprecated AdminBarRemoval sniff, so it should probably be deprecated as well.

  3. I'm presuming you meant to amend commit c1736c2 with commit e6b90a2 ? If so, something went wrong there. You may want to have a look at that.

  4. As it looks like this PR will be ready in time for the WPCS 1.0.0 release, please incorporate the changes from Add note regarding WordPress-VIP ruleset #1403 + the additional changes suggested in the comments in that PR.

  5. I've confirmed that there is trailing whitespace in the VIP XML ruleset. Please tidy it up.


N.B. The AbstractArrayAssignmentRestrictionsSniff can not be deprecated as it is still in use by the DB.SlowDBQuery and the WP.PostsPerPage sniffs which will not be deprecated.

*
* @var bool
*/
public $error = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm presuming this is a copy/paste error as I don't understand why this property would be added.
Please remove it here and everywhere else where it was inadvertently copied into.

@@ -71,15 +94,15 @@ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff {
*/
protected $target_css_properties = array(
'visibility' => array(
'type' => '!=',
'type' => '!=',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo this formatting change, here and in the lines below it.

);
}

if ( false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FoundPropertyForDeprecatedSniff error message is only needed when a sniff has public properties which could be set/changed from within a custom ruleset.

Before throwing the warning, you need to actually check whether the properties have been set from the ruleset, i.e. whether the values for public properties this class uses have been changed.

For this sniff, the only relevant property is the $remove_only property. The warning should only be thrown when the value for that property is something other than true.

See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#admin-bar-visibility-manipulations

* @return array <int line number> => <int number of warnings>
*/
public function getWarningList() {
return array();
public function getWarningList( $testFile = '' ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs some work.

  • Regarding the switch: one of the two cases is wrong - both currently refer to the AdminBarRemovalUnitTest.css file.
  • Also, all cases contain a return, so the return statement underneath the switch will never be reached.
  • Lastly, the alignment of the double arrows in the arrays in the case statements is off.

Either way, the function needs to be changed.

);
}

if ( ! empty( $this->exclude )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sniff also has an error property which can be changed from within a custom ruleset, so the condition needs to check the value of that property too.

See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#error-type-for-file-system-writes

Unit tests need to be added to the unit test case file with the non-default property values to make sure the deprecated property warning is thrown correctly.

&& false === $this->thrown['FoundPropertyForDeprecatedSniff']
) {
$this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.SessionFunctionsUsageSniff" sniff has been deprecated. Please update your custom ruleset.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👉 See previous remark - remove Sniff

@@ -46,6 +69,24 @@ public function register() {
* @return void
*/
public function process_token( $stackPtr ) {
if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.SessionVariableUsageSniff" sniff has been deprecated. Please update your custom ruleset.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👉 See previous remark - remove Sniff

*/
private $thrown = array(
'DeprecatedSniff' => false,
'FoundPropertyForDeprecatedSniff' => false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sniff does not have any public properties which can be changed, so the FoundPropertyForDeprecatedSniff entry can be removed.

);
}

if ( ! empty( $this->exclude )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sniff does not have any public properties which can be changed, so this complete code block for the FoundPropertyForDeprecatedSniff warning can be removed.

@@ -43,6 +66,24 @@ public function register() {
* @return void
*/
public function process_token( $stackPtr ) {
if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.SessionVariableUsageSniff" sniff has been deprecated. Please update your custom ruleset.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

References the wrong sniff: WordPress.VIP.SessionVariableUsageSniff should be WordPress.VIP.SuperGlobalInputUsage.

@tomjn
Copy link
Contributor Author

tomjn commented Jul 9, 2018

I've addressed a lot of the feedback, integrated the changes suggested in #1403, todo items:

  • check each sniff for parameters and add appropriate FoundPropertyForDeprecatedSniff notices
  • update unit tests with new checks, not entirely sure how to do that though for sniff parameters
  • Figure out squashing c1736c2 and e6b90a2 into eachother

@tomjn tomjn force-pushed the vip-migrate-filesystem-write-disallow-sniff branch from 8ace487 to e62bf21 Compare July 9, 2018 19:01
@tomjn tomjn force-pushed the vip-migrate-filesystem-write-disallow-sniff branch from a3b7b84 to 20494c4 Compare July 10, 2018 12:08
@tomjn
Copy link
Contributor Author

tomjn commented Jul 10, 2018

So an updated TODO list:

  • adjust unit tests
  • add checks for parameters on sniffs
  • amend the VIP deprecation paragraph

@jrfnl jrfnl mentioned this pull request Jul 10, 2018
10 tasks
@jrfnl
Copy link
Member

jrfnl commented Jul 12, 2018

@tomjn Just checking in... will you be able to finish the work on this PR tomorrow so we can include it in the WPCS 1.0.0 release ? 🙏

@tomjn
Copy link
Contributor Author

tomjn commented Jul 13, 2018

Yesterday was my birthday so I took some time AFK, it's on my todo list though for later today

@jrfnl
Copy link
Member

jrfnl commented Jul 13, 2018

@tomjn 👍 and happy birthday and many happy returns! 🎉

@tomjn
Copy link
Contributor Author

tomjn commented Jul 13, 2018

As far as I can tell, all the parameters for the VIP sniffs are already handled, moving on to unit tests

@tomjn
Copy link
Contributor Author

tomjn commented Jul 13, 2018

For reference I'm using the VIP Slow DB Query tests as a basis since the majority of what I need to do work wise is near identical

<?php

// @codingStandardsChangeSetting WordPress.VIP.SlowDBQuery exclude something
$query = 'foo=bar&meta_key=foo';

// @codingStandardsChangeSetting WordPress.VIP.SlowDBQuery exclude false

@tomjn tomjn force-pushed the vip-migrate-filesystem-write-disallow-sniff branch from 14e6919 to 4573545 Compare July 13, 2018 17:50
@tomjn tomjn force-pushed the vip-migrate-filesystem-write-disallow-sniff branch from 4573545 to 50c3471 Compare July 13, 2018 23:21
@tomjn
Copy link
Contributor Author

tomjn commented Jul 14, 2018

The travis builds seem a bit.. off, hmm, only thing to do is the final wording of the VIP deprecation paragraph

@jrfnl
Copy link
Member

jrfnl commented Jul 14, 2018

The travis builds seem a bit.. off

I restarted the one build which errored out and Travis is ok now.

@jrfnl
Copy link
Member

jrfnl commented Jul 15, 2018

@tomjn How can we help you to finish the PR ?

@tomjn
Copy link
Contributor Author

tomjn commented Jul 15, 2018

@jrfnl It's just the paragraph for the readme that needs doing, but my mind is blank. I'm also pretty tired out from the last week and have a busy week ahead of me. Chances are I won't be able to do much more on this for a few days, and that all that's actually needed is less than 20 characters of prose.

@jrfnl
Copy link
Member

jrfnl commented Jul 15, 2018

@tomjn Hmm... maybe @GaryJones can come up with some good phrasing ?
The 1.0.0 release is waiting on this PR and is already two weeks overdue now, so it would really help if we can finish this off now.

@GaryJones
Copy link
Member

I'll come up with something today.

@GaryJones
Copy link
Member

@jrfnl If the rest of the PR is good, then let's merge it, and I'll re-do my other PR for the readme - that way, we won't be waiting on Tom to merge readme changes into his branch before merging his branch into develop.

@GaryJones
Copy link
Member

GaryJones commented Jul 16, 2018

This WPCS package contains the sniffs for another ruleset, WordPress-VIP. This ruleset was originally intended to aid with the WordPress.com VIP coding requirements, but this is no longer used or recommended by the WordPress.com VIP team or their clients, since they prefer to use their official VIP coding standards ruleset instead.

Before WPCS 1.0.0, the WordPress-VIP ruleset was included as part of the complete WordPress ruleset. As of 1.0.0 the WordPress-VIP ruleset is not part of the WordPress ruleset, and it is deprecated. The remaining WordPress-VIP sniffs may still be referenced in custom rulesets, so to maintain some backwards compatibility, they will remain in WPCS until 2.0.0. See #1309 for more information.

@tomjn
Copy link
Contributor Author

tomjn commented Jul 16, 2018

@jrfnl I've updated the PR with the version @GaryJones wrote, thanks for the wordsmithing :)

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this baby!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants