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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5585804
Deprecated the VIP FileSystemWritesDisallow Sniff and the Admin Bar …
tomjn Jul 6, 2018
4ae8691
deprecate the VIP Order By Rand sniff
tomjn Jul 6, 2018
ea7493b
Deprecated the VIP RestrictedFunctions Sniff
tomjn Jul 6, 2018
df07c46
deprecated the VIP sniff RestrictedVariables
tomjn Jul 6, 2018
907fd88
deprecates the VIP SessionFunctionsUsage sniff
tomjn Jul 6, 2018
d1272dd
Deprecated the VIP SessionVariableUsageSniff sniff
tomjn Jul 6, 2018
7106b30
Deprecated the VIP sniff SuperGlobalInputUsageSniff
tomjn Jul 6, 2018
42d1ef0
resolve PHPCBF formatting issues by adding commars and removing trail…
tomjn Jul 7, 2018
cafaf2a
update the VIP rulesets description to indicate that it's deprecated,…
tomjn Jul 7, 2018
95581c0
Fixes for the VIP Sniff deprecations based on Juliettes review
tomjn Jul 8, 2018
9faef43
Deprecated AbstractVariableRestrictionsSniff
tomjn Jul 9, 2018
a4db740
deprecated the has_html_open_tag method in Sniff class
tomjn Jul 9, 2018
4b50df5
Remove VIP from the standard WP ruleset
tomjn Jul 9, 2018
ad1c014
unit test fixes
tomjn Jul 9, 2018
9c1e44f
Fixes stray whitespace characters in the WP ruleset, and yoda conditi…
tomjn Jul 9, 2018
e3206b7
Apply spelling and grammar corrections to VIP deprecations
tomjn Jul 10, 2018
20494c4
merges the xml comment in the VIP ruleset into the description
tomjn Jul 10, 2018
50c3471
test the exclude parameter deprecation in the deprecated VIP sniff un…
tomjn Jul 13, 2018
50c6d77
Updated the VIP deprecation notice in the readme to read better
tomjn Jul 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ You can use the following as standard names when invoking `phpcs` to select snif
- `WordPress-Docs` - additional ruleset for [WordPress inline documentation standards](https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/)
- `WordPress-Extra` - extended ruleset for recommended best practices, not sufficiently covered in the WordPress core coding standards
- includes `WordPress-Core`
- `WordPress-VIP` - extended ruleset for [WordPress.com VIP coding requirements](https://vip.wordpress.com/documentation/code-review-what-we-look-for/)
- includes `WordPress-Core`

**Notes:** 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](https://vip.wordpress.com/documentation/code-review-what-we-look-for/), 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](https://github.com/Automattic/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](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1309) for more information.

### Using a custom ruleset

Expand Down
54 changes: 47 additions & 7 deletions WordPress-VIP/ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset name="WordPress VIP">
<description>WordPress.com VIP Coding Standards</description>
<description>Deprecated WordPress.com VIP Coding Standards, use the official VIP coding standards instead, these can be found at https://github.com/Automattic/VIP-Coding-Standards</description>

<autoload>./../WordPress/PHPCSAliases.php</autoload>

Expand Down Expand Up @@ -131,7 +131,12 @@
#############################################################################
-->

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.AdminBarRemoval.DeprecatedSniff">
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.DirectDatabaseQuery.DeprecatedSniff">
<severity>0</severity>
</rule>
Expand All @@ -147,7 +152,7 @@
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.SlowDBQuery.DeprecatedSniff">
<severity>0</severity>
</rule>
Expand All @@ -169,7 +174,7 @@
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.PluginMenuSlug.DeprecatedSniff">
<severity>0</severity>
</rule>
Expand All @@ -179,7 +184,7 @@
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.ValidatedSanitizedInput.DeprecatedSniff">
<severity>0</severity>
</rule>
Expand All @@ -198,7 +203,7 @@
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.CronInterval.DeprecatedSniff">
<severity>0</severity>
</rule>
Expand All @@ -211,7 +216,42 @@
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.FileSystemWritesDisallow.DeprecatedSniff">
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.OrderByRand.DeprecatedSniff">
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.RestrictedFunctions.DeprecatedSniff">
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.RestrictedVariables.DeprecatedSniff">
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.SessionFunctionsUsage.DeprecatedSniff">
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.SessionVariableUsage.DeprecatedSniff">
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.SuperGlobalInputUsage.DeprecatedSniff">
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitly included. -->
<rule ref="WordPress.VIP.TimezoneChange.DeprecatedSniff">
<severity>0</severity>
</rule>
Expand Down
2 changes: 2 additions & 0 deletions WordPress/AbstractVariableRestrictionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* `WordPress_Sniffs_Variables_VariableRestrictionsSniff` to
* `WordPress_AbstractVariableRestrictionsSniff`.
* @since 0.11.0 Extends the WordPress_Sniff class.
*
* @deprecated 1.0.0 All sniffs depending on this class were deprecated.
*/
abstract class AbstractVariableRestrictionsSniff extends Sniff {

Expand Down
1 change: 1 addition & 0 deletions WordPress/Sniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,7 @@ public function get_declared_namespace_name( $stackPtr ) {
* originally created.
* @since 0.13.0 The $stackPtr parameter is now optional. Either that or the
* $content parameter has to be passed.
* @deprecated 1.0.0 This method is only used by deprecated sniffs.
*
* @param string $tag_name The name of the HTML tag without brackets. So if
* searching for '<span...', this would be 'span'.
Expand Down
37 changes: 36 additions & 1 deletion WordPress/Sniffs/VIP/AdminBarRemovalSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,25 @@
* - Added the $remove_only property.
* - Now also sniffs for manipulation of the admin bar visibility through CSS.
* @since 0.13.0 Class name changed: this class is now namespaced.
*
* @deprecated 1.0.0 This sniff has been deprecated.
* This file remains for now to prevent BC breaks.
*/
class AdminBarRemovalSniff extends AbstractFunctionParameterSniff {

/**
* Keep track of whether the warnings have been thrown to prevent
* the messages being thrown for every token triggering the sniff.
*
* @since 1.0.0
*
* @var array
*/
private $thrown = array(
'DeprecatedSniff' => false,
'FoundPropertyForDeprecatedSniff' => false,
);

/**
* A list of tokenizers this sniff supports.
*
Expand Down Expand Up @@ -167,7 +183,9 @@ public function register() {
}

/**
* Processes this test, when one of its tokens is encountered.
* Process the token and handle the deprecation notices.
*
* @since 1.0.0 Adjusted to allow for throwing the deprecation notices.
*
* @param int $stackPtr The position of the current token in the stack.
*
Expand All @@ -176,6 +194,23 @@ public function register() {
*/
public function process_token( $stackPtr ) {

if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.AdminBarRemoval" sniff has been deprecated. Please update your custom ruleset.',
0,
'DeprecatedSniff'
);
}

if ( ( true !== $this->remove_only ) &&
false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) {
$this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.AdminBarRemoval" sniff has been deprecated. Please update your custom ruleset.',
0,
'FoundPropertyForDeprecatedSniff'
);
}

$file_name = $this->phpcsFile->getFileName();
$file_extension = substr( strrchr( $file_name, '.' ), 1 );

Expand Down
47 changes: 47 additions & 0 deletions WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* @since 0.11.0 Extends the WordPress_AbstractFunctionRestrictionsSniff instead of the
* Generic_Sniffs_PHP_ForbiddenFunctionsSniff.
* @since 0.13.0 Class name changed: this class is now namespaced.
*
* @deprecated 1.0.0 This sniff has been deprecated.
* This file remains for now to prevent BC breaks.
*/
class FileSystemWritesDisallowSniff extends AbstractFunctionRestrictionsSniff {

Expand All @@ -32,6 +35,19 @@ class FileSystemWritesDisallowSniff extends AbstractFunctionRestrictionsSniff {
*/
public $error = true;

/**
* Keep track of whether the warnings have been thrown to prevent
* the messages being thrown for every token triggering the sniff.
*
* @since 1.0.0
*
* @var array
*/
private $thrown = array(
'DeprecatedSniff' => false,
'FoundPropertyForDeprecatedSniff' => false,
);

/**
* Groups of functions to restrict.
*
Expand Down Expand Up @@ -102,4 +118,35 @@ public function getGroups() {
return $groups;
}

/**
* Process the token and handle the deprecation notices.
*
* @since 1.0.0 Added to allow for throwing the deprecation notices.
*
* @param int $stackPtr The position of the current token in the stack.
*
* @return void|int
*/
public function process_token( $stackPtr ) {
if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.FileSystemWritesDisallow" sniff has been deprecated. Please update your custom ruleset.',
0,
'DeprecatedSniff'
);
}

if ( ( ! empty( $this->exclude ) || true !== $this->error )
&& false === $this->thrown['FoundPropertyForDeprecatedSniff']
) {
$this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.FileSystemWritesDisallow" sniff has been deprecated. Please update your custom ruleset.',
0,
'FoundPropertyForDeprecatedSniff'
);
}

return parent::process_token( $stackPtr );
}

}
47 changes: 47 additions & 0 deletions WordPress/Sniffs/VIP/OrderByRandSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@
*
* @since 0.9.0
* @since 0.13.0 Class name changed: this class is now namespaced.
*
* @deprecated 1.0.0 This sniff has been deprecated.
* This file remains for now to prevent BC breaks.
*/
class OrderByRandSniff extends AbstractArrayAssignmentRestrictionsSniff {

/**
* Keep track of whether the warnings have been thrown to prevent
* the messages being thrown for every token triggering the sniff.
*
* @since 1.0.0
*
* @var array
*/
private $thrown = array(
'DeprecatedSniff' => false,
'FoundPropertyForDeprecatedSniff' => false,
);

/**
* Groups of variables to restrict.
*
Expand All @@ -39,6 +55,37 @@ public function getGroups() {
);
}

/**
* Process the token and handle the deprecation notices.
*
* @since 1.0.0 Added to allow for throwing the deprecation notices.
*
* @param int $stackPtr The position of the current token in the stack.
*
* @return void|int
*/
public function process_token( $stackPtr ) {
if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.OrderByRand" sniff has been deprecated. Please update your custom ruleset.',
0,
'DeprecatedSniff'
);
}

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.

A unit test should be added to test that the deprecated property warning is thrown correctly.

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

return parent::process_token( $stackPtr );
}

/**
* Callback to process each confirmed key, to check value
* This must be extended to add the logic to check assignment value
Expand Down
47 changes: 47 additions & 0 deletions WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,25 @@
* WordPress_Sniffs_WP_AlternativeFunctionsSniff.
* The check for `eval()` now defers to the upstream Squiz.PHP.Eval sniff.
* @since 0.13.0 Class name changed: this class is now namespaced.
*
* @deprecated 1.0.0 This sniff has been deprecated.
* This file remains for now to prevent BC breaks.
*/
class RestrictedFunctionsSniff extends AbstractFunctionRestrictionsSniff {

/**
* Keep track of whether the warnings have been thrown to prevent
* the messages being thrown for every token triggering the sniff.
*
* @since 1.0.0
*
* @var array
*/
private $thrown = array(
'DeprecatedSniff' => false,
'FoundPropertyForDeprecatedSniff' => false,
);

/**
* Groups of functions to restrict.
*
Expand Down Expand Up @@ -225,4 +241,35 @@ public function getGroups() {
);
}

/**
* Process the token and handle the deprecation notices.
*
* @since 1.0.0 Added to allow for throwing the deprecation notices.
*
* @param int $stackPtr The position of the current token in the stack.
*
* @return void|int
*/
public function process_token( $stackPtr ) {
if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.RestrictedFunctions" sniff has been deprecated. Please update your custom ruleset.',
0,
'DeprecatedSniff'
);
}

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.

A unit test should be added to test that the deprecated property warning is thrown correctly.

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

return parent::process_token( $stackPtr );
}

}
Loading