Skip to content

Commit 714bc00

Browse files
authored
Merge pull request #839 from Automattic/feature/deprecate-js-only-sniffs
2 parents d7d1ce2 + f0f80e0 commit 714bc00

File tree

8 files changed

+187
-8
lines changed

8 files changed

+187
-8
lines changed

WordPress-VIP-Go/ruleset.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
<!-- The rules below are the changes from between the original sniff or parent ruleset, and what should be applied for this Standard. -->
66
<!-- Include the base VIP Minimum ruleset -->
7-
<rule ref="WordPressVIPMinimum"/>
7+
<rule ref="WordPressVIPMinimum">
8+
<exclude name="WordPressVIPMinimum.JS"/>
9+
</rule>
810

911
<!-- Things that may be incompatible with the VIP Go infrastructure and needs a dev to review -->
1012
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents">

WordPressVIPMinimum/Sniffs/JS/DangerouslySetInnerHTMLSniff.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace WordPressVIPMinimum\Sniffs\JS;
99

10+
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
1011
use PHP_CodeSniffer\Util\Tokens;
1112
use WordPressVIPMinimum\Sniffs\Sniff;
1213

@@ -15,7 +16,7 @@
1516
*
1617
* Looks for instances of React's dangerouslySetInnerHMTL.
1718
*/
18-
class DangerouslySetInnerHTMLSniff extends Sniff {
19+
class DangerouslySetInnerHTMLSniff extends Sniff implements DeprecatedSniff {
1920

2021
/**
2122
* A list of tokenizers this sniff supports.
@@ -67,4 +68,31 @@ public function process_token( $stackPtr ) {
6768
$data = [ $this->tokens[ $stackPtr ]['content'] ];
6869
$this->phpcsFile->addError( $message, $stackPtr, 'Found', $data );
6970
}
71+
72+
/**
73+
* Provide the version number in which the sniff was deprecated.
74+
*
75+
* @return string
76+
*/
77+
public function getDeprecationVersion() {
78+
return 'VIP-Coding-Standard v3.1.0';
79+
}
80+
81+
/**
82+
* Provide the version number in which the sniff will be removed.
83+
*
84+
* @return string
85+
*/
86+
public function getRemovalVersion() {
87+
return 'VIP-Coding-Standard v4.0.0';
88+
}
89+
90+
/**
91+
* Provide a custom message to display with the deprecation.
92+
*
93+
* @return string
94+
*/
95+
public function getDeprecationMessage() {
96+
return 'Support for scanning JavaScript files will be removed from PHP_CodeSniffer, so this sniff is no longer viable.';
97+
}
7098
}

WordPressVIPMinimum/Sniffs/JS/HTMLExecutingFunctionsSniff.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace WordPressVIPMinimum\Sniffs\JS;
99

10+
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
1011
use PHP_CodeSniffer\Util\Tokens;
1112
use WordPressVIPMinimum\Sniffs\Sniff;
1213

@@ -15,7 +16,7 @@
1516
*
1617
* Flags functions which are executing HTML passed to it.
1718
*/
18-
class HTMLExecutingFunctionsSniff extends Sniff {
19+
class HTMLExecutingFunctionsSniff extends Sniff implements DeprecatedSniff {
1920

2021
/**
2122
* List of HTML executing functions.
@@ -128,4 +129,31 @@ public function process_token( $stackPtr ) {
128129
}
129130
}
130131
}
132+
133+
/**
134+
* Provide the version number in which the sniff was deprecated.
135+
*
136+
* @return string
137+
*/
138+
public function getDeprecationVersion() {
139+
return 'VIP-Coding-Standard v3.1.0';
140+
}
141+
142+
/**
143+
* Provide the version number in which the sniff will be removed.
144+
*
145+
* @return string
146+
*/
147+
public function getRemovalVersion() {
148+
return 'VIP-Coding-Standard v4.0.0';
149+
}
150+
151+
/**
152+
* Provide a custom message to display with the deprecation.
153+
*
154+
* @return string
155+
*/
156+
public function getDeprecationMessage() {
157+
return 'Support for scanning JavaScript files will be removed from PHP_CodeSniffer, so this sniff is no longer viable.';
158+
}
131159
}

WordPressVIPMinimum/Sniffs/JS/InnerHTMLSniff.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace WordPressVIPMinimum\Sniffs\JS;
99

10+
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
1011
use PHP_CodeSniffer\Util\Tokens;
1112
use WordPressVIPMinimum\Sniffs\Sniff;
1213

@@ -15,7 +16,7 @@
1516
*
1617
* Looks for instances of .innerHMTL.
1718
*/
18-
class InnerHTMLSniff extends Sniff {
19+
class InnerHTMLSniff extends Sniff implements DeprecatedSniff {
1920

2021
/**
2122
* A list of tokenizers this sniff supports.
@@ -81,4 +82,31 @@ public function process_token( $stackPtr ) {
8182
$this->phpcsFile->addWarning( $message, $stackPtr, 'Found', $data );
8283
}
8384
}
85+
86+
/**
87+
* Provide the version number in which the sniff was deprecated.
88+
*
89+
* @return string
90+
*/
91+
public function getDeprecationVersion() {
92+
return 'VIP-Coding-Standard v3.1.0';
93+
}
94+
95+
/**
96+
* Provide the version number in which the sniff will be removed.
97+
*
98+
* @return string
99+
*/
100+
public function getRemovalVersion() {
101+
return 'VIP-Coding-Standard v4.0.0';
102+
}
103+
104+
/**
105+
* Provide a custom message to display with the deprecation.
106+
*
107+
* @return string
108+
*/
109+
public function getDeprecationMessage() {
110+
return 'Support for scanning JavaScript files will be removed from PHP_CodeSniffer, so this sniff is no longer viable.';
111+
}
84112
}

WordPressVIPMinimum/Sniffs/JS/StringConcatSniff.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace WordPressVIPMinimum\Sniffs\JS;
99

10+
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
1011
use PHP_CodeSniffer\Util\Tokens;
1112
use WordPressVIPMinimum\Sniffs\Sniff;
1213

@@ -15,7 +16,7 @@
1516
*
1617
* Looks for HTML string concatenation.
1718
*/
18-
class StringConcatSniff extends Sniff {
19+
class StringConcatSniff extends Sniff implements DeprecatedSniff {
1920

2021
/**
2122
* A list of tokenizers this sniff supports.
@@ -72,4 +73,31 @@ private function addFoundError( $stackPtr, array $data ) {
7273
$message = 'HTML string concatenation detected, this is a security risk, use DOM node construction or a templating language instead: %s.';
7374
$this->phpcsFile->addError( $message, $stackPtr, 'Found', $data );
7475
}
76+
77+
/**
78+
* Provide the version number in which the sniff was deprecated.
79+
*
80+
* @return string
81+
*/
82+
public function getDeprecationVersion() {
83+
return 'VIP-Coding-Standard v3.1.0';
84+
}
85+
86+
/**
87+
* Provide the version number in which the sniff will be removed.
88+
*
89+
* @return string
90+
*/
91+
public function getRemovalVersion() {
92+
return 'VIP-Coding-Standard v4.0.0';
93+
}
94+
95+
/**
96+
* Provide a custom message to display with the deprecation.
97+
*
98+
* @return string
99+
*/
100+
public function getDeprecationMessage() {
101+
return 'Support for scanning JavaScript files will be removed from PHP_CodeSniffer, so this sniff is no longer viable.';
102+
}
75103
}

WordPressVIPMinimum/Sniffs/JS/StrippingTagsSniff.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace WordPressVIPMinimum\Sniffs\JS;
99

10+
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
1011
use PHP_CodeSniffer\Util\Tokens;
1112
use WordPressVIPMinimum\Sniffs\Sniff;
1213

@@ -15,7 +16,7 @@
1516
*
1617
* Looks for incorrect way of stripping tags.
1718
*/
18-
class StrippingTagsSniff extends Sniff {
19+
class StrippingTagsSniff extends Sniff implements DeprecatedSniff {
1920

2021
/**
2122
* A list of tokenizers this sniff supports.
@@ -70,4 +71,31 @@ public function process_token( $stackPtr ) {
7071
$this->phpcsFile->addError( $message, $stackPtr, 'VulnerableTagStripping' );
7172
}
7273
}
74+
75+
/**
76+
* Provide the version number in which the sniff was deprecated.
77+
*
78+
* @return string
79+
*/
80+
public function getDeprecationVersion() {
81+
return 'VIP-Coding-Standard v3.1.0';
82+
}
83+
84+
/**
85+
* Provide the version number in which the sniff will be removed.
86+
*
87+
* @return string
88+
*/
89+
public function getRemovalVersion() {
90+
return 'VIP-Coding-Standard v4.0.0';
91+
}
92+
93+
/**
94+
* Provide a custom message to display with the deprecation.
95+
*
96+
* @return string
97+
*/
98+
public function getDeprecationMessage() {
99+
return 'Support for scanning JavaScript files will be removed from PHP_CodeSniffer, so this sniff is no longer viable.';
100+
}
73101
}

WordPressVIPMinimum/Sniffs/JS/WindowSniff.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace WordPressVIPMinimum\Sniffs\JS;
99

10+
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
1011
use PHP_CodeSniffer\Util\Tokens;
1112
use WordPressVIPMinimum\Sniffs\Sniff;
1213

@@ -15,7 +16,7 @@
1516
*
1617
* Looks for instances of window properties that should be flagged.
1718
*/
18-
class WindowSniff extends Sniff {
19+
class WindowSniff extends Sniff implements DeprecatedSniff {
1920

2021
/**
2122
* A list of tokenizers this sniff supports.
@@ -125,4 +126,31 @@ public function process_token( $stackPtr ) {
125126
$message = 'Data from JS global "%s" may contain user-supplied values and should be sanitized before output to prevent XSS.';
126127
$this->phpcsFile->addError( $message, $stackPtr, $nextNextToken, $data );
127128
}
129+
130+
/**
131+
* Provide the version number in which the sniff was deprecated.
132+
*
133+
* @return string
134+
*/
135+
public function getDeprecationVersion() {
136+
return 'VIP-Coding-Standard v3.1.0';
137+
}
138+
139+
/**
140+
* Provide the version number in which the sniff will be removed.
141+
*
142+
* @return string
143+
*/
144+
public function getRemovalVersion() {
145+
return 'VIP-Coding-Standard v4.0.0';
146+
}
147+
148+
/**
149+
* Provide a custom message to display with the deprecation.
150+
*
151+
* @return string
152+
*/
153+
public function getDeprecationMessage() {
154+
return 'Support for scanning JavaScript files will be removed from PHP_CodeSniffer, so this sniff is no longer viable.';
155+
}
128156
}

WordPressVIPMinimum/ruleset.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
descriptive error message during the loading of the ruleset instead of
1010
a fatal "class not found" error once the sniffs start running.
1111
-->
12-
<rule ref="PHPCSUtils"/>
12+
<rule ref="PHPCSUtils">
13+
<!--
14+
Exclude all JS specific sniffs. These are deprecated and should no longer be used.
15+
16+
Note: While this exclusion has nothing to do with PHPCSUtils, exclusions must be placed within a "rule"
17+
and as all sniffs from WordPressVIPMinimum are automatically included, we don't have a WordPressVIPMinimum
18+
rule in which to place the exclusion, so this will have to do for now.
19+
-->
20+
<exclude name="WordPressVIPMinimum.JS"/>
21+
</rule>
1322

1423
<rule ref="Generic.PHP.Syntax"/>
1524
<rule ref="Generic.PHP.NoSilencedErrors">

0 commit comments

Comments
 (0)