Automattic / VIP-Coding-Standards

PHP_CodeSniffer ruleset to enforce WordPress VIP coding standards.
https://wpvip.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/
Other
236 stars 40 forks source link

Replace deprecated WordPress.WP.TimezoneChange sniff #452

Closed kevinfodness closed 4 years ago

kevinfodness commented 4 years ago

Bug Description

With the release of wpcs v2.2.0 on 2019-11-11, the WordPress.WP.TimezoneChange sniff was deprecated in favor of WordPress.DateTime.RestrictedFunctions. Recommend switching to the new sniff name.

Minimal Code Snippet

Create a test file called test.php with the following contents:

<?php
$date = date( DATE_W3C );

Then run the WordPressVIPMinimum standard against that file:

phpcs --standard=WordPressVIPMinimum test.php

Or using the WordPress-VIP-Go standard:

phpcs --standard=WordPress-VIP-Go test.php

Error Code

FILE: /Users/kevinfodness/Desktop/vipwpcs/test.php
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 1 | WARNING | The "WordPress.WP.TimezoneChange" sniff has been deprecated. Use the "WordPress.DateTime.RestrictedFunctions" sniff instead. Please update your custom ruleset.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Environment

Use php -v and composer show to get versions.

Question Answer
PHP version 7.3.0
PHP_CodeSniffer version 3.5.2
VIPCS version 2.0.0

Additional Context (optional)

The difficulty with a fix here is that the new standard was introduced and the old standard was deprecated in the same release, so if users have an older version of wpcs but the latest version of vipcs then they would get a sniff not found error. However, we (and I assume others) rely on clean output of phpcs in Travis in order to pass a PR, and the deprecation warning is causing all of our automated CI checks to fail, so it would be nice if it was fixed in the upstream.

Tested Against master branch?

Additionally, I tested against the develop branch and checked for open issues or PRs relating to this issue and didn't find any.

simonwheatley commented 4 years ago

Noted in JIRA as [GH-3337]

kevinfodness commented 4 years ago

PR created: #453