Skip to content

Commit 67e4675

Browse files
authored
Merge pull request #169 from Automattic/updated-messaging
use backticks around code elements; fix a few typos
2 parents ed9a78c + 3556bb7 commit 67e4675

19 files changed

+47
-47
lines changed

WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ private function processFunctionBody( $stackPtr, $variableName ) {
248248
}
249249
} elseif ( $this->isInsideIfConditonal( $wpQueryVarUsed ) ) {
250250
if ( ! $this->isParentConditionalCheckingMainQuery( $wpQueryVarUsed ) ) {
251-
$this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'PreGetPosts' );
251+
$this->_phpcsFile->addWarning( 'Main WP_Query is being modified without `$query->is_main_query()` check. Needs manual inspection.', $wpQueryVarUsed, 'PreGetPosts' );
252252
}
253253
} elseif ( $this->isWPQueryMethodCall( $wpQueryVarUsed, 'set' ) ) {
254-
$this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'PreGetPosts' );
254+
$this->_phpcsFile->addWarning( 'Main WP_Query is being modified without `$query->is_main_query()` check. Needs manual inspection.', $wpQueryVarUsed, 'PreGetPosts' );
255255
}
256256
$wpQueryVarUsed = $this->_phpcsFile->findNext(
257257
array( T_VARIABLE ), // types.

WordPressVIPMinimum/Sniffs/Cache/BatcacheWhitelistedParamsSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function process( File $phpcsFile, $stackPtr ) {
106106
$variable_name = substr( $variable_name, 1, -1 );
107107

108108
if ( true === in_array( $variable_name, $this->whitelistes_batcache_params, true ) ) {
109-
$phpcsFile->addWarning( sprintf( 'Batcache whitelisted GET param, %s, found. Batcache whitelisted parameters get stripped and are not available in PHP.', $variable_name ), $stackPtr, 'strippedGetParam' );
109+
$phpcsFile->addWarning( sprintf( 'Batcache whitelisted GET param, `%s`, found. Batcache whitelisted parameters get stripped and are not available in PHP.', $variable_name ), $stackPtr, 'strippedGetParam' );
110110
return;
111111
}
112112
}//end process()

WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function process( File $phpcsFile, $stackPtr ) {
9797
$valueAfterEqualSign = $phpcsFile->findNext( Tokens::$emptyTokens, ( $rightAfterNextVariableOccurence + 1 ), null, true, null, true );
9898

9999
if ( T_FALSE === $tokens[ $valueAfterEqualSign ]['code'] ) {
100-
$phpcsFile->addError( sprintf( 'Obtained cached value in %s is being overriden. Disabling caching?', $variableName ), $nextVariableOccurrence, 'CacheValueOverride' );
100+
$phpcsFile->addError( sprintf( 'Obtained cached value in `%s` is being overriden. Disabling caching?', $variableName ), $nextVariableOccurrence, 'CacheValueOverride' );
101101
}
102102

103103
} //end Process()

WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private function addError( $parentClassName, $methodName, $currentMethodSignatur
303303

304304
$parentSignature = sprintf( '%s::%s(%s)', $parentClassName, $methodName, implode( ', ', $this->generateParamList( $parentMethodSignature ) ) );
305305

306-
$phpcsFile->addError( sprintf( 'Declaration of %s should be compatible with %s', $currentSignature, $parentSignature ), $stackPtr, 'DeclarationCompatibility' );
306+
$phpcsFile->addError( sprintf( 'Declaration of `%s` should be compatible with `%s`', $currentSignature, $parentSignature ), $stackPtr, 'DeclarationCompatibility' );
307307
}//end addError()
308308

309309
/**

WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function process( File $phpcsFile, $stackPtr ) {
7373
}
7474

7575
if ( T_STRING === $tokens[ $stackPtr ]['code'] && true === in_array( $constantName, $this->restrictedConstantNames, true ) ) {
76-
$phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $stackPtr, 'ConstantRestrictions' );
76+
$phpcsFile->addWarning( sprintf( 'Code is touching the `%s` constant. Make sure it\'s used appropriately.', $constantName ), $stackPtr, 'ConstantRestrictions' );
7777
return;
7878
}
7979

@@ -101,9 +101,9 @@ public function process( File $phpcsFile, $stackPtr ) {
101101

102102
if ( true === in_array( $tokens[ $previous ]['code'], Tokens::$functionNameTokens, true ) ) {
103103
if ( 'define' === $tokens[ $previous ]['content'] ) {
104-
$phpcsFile->addError( sprintf( 'The definition of %s constant is prohibited. Please use a different name.', $constantName ), $previous, 'ConstantRestrictions' );
104+
$phpcsFile->addError( sprintf( 'The definition of `%s` constant is prohibited. Please use a different name.', $constantName ), $previous, 'ConstantRestrictions' );
105105
} elseif ( true === in_array( $constantName, $this->restrictedConstantNames, true ) ) {
106-
$phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $previous, 'ConstantRestrictions' );
106+
$phpcsFile->addWarning( sprintf( 'Code is touching the `%s` constant. Make sure it\'s used appropriately.', $constantName ), $previous, 'ConstantRestrictions' );
107107
}
108108
}
109109
}

WordPressVIPMinimum/Sniffs/Constants/ConstantStringSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function process( File $phpcsFile, $stackPtr ) {
6161
$nextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextToken + 1 ), null, true, null, true );
6262

6363
if ( T_CONSTANT_ENCAPSED_STRING !== $tokens[ $nextToken ]['code'] ) {
64-
$phpcsFile->addError( sprintf( 'Constant name, as a string, should be used along with %s().', $tokens[ $stackPtr ]['content'] ), $nextToken, 'NotCheckingConstantName' );
64+
$phpcsFile->addError( sprintf( 'Constant name, as a string, should be used along with `%s()`.', $tokens[ $stackPtr ]['content'] ), $nextToken, 'NotCheckingConstantName' );
6565
return;
6666
}
6767

WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function process( File $phpcsFile, $stackPtr ) {
101101
}
102102

103103
if ( T_VARIABLE === $tokens[ $nextToken ]['code'] ) {
104-
$phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
104+
$phpcsFile->addWarning( sprintf( 'File inclusion using variable (`%s`). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
105105
return;
106106
}
107107

@@ -119,18 +119,18 @@ public function process( File $phpcsFile, $stackPtr ) {
119119

120120
if ( true === in_array( $tokens[ $nextToken ]['content'], array_keys( $this->restrictedConstants ), true ) ) {
121121
// The construct is using one of the restricted constants.
122-
$phpcsFile->addError( sprintf( '%s constant might not be defined or available. Use %s instead.', $tokens[ $nextToken ]['content'], $this->restrictedConstants[ $tokens[ $nextToken ]['content'] ] ), $nextToken );
122+
$phpcsFile->addError( sprintf( '`%s` constant might not be defined or available. Use `%s()` instead.', $tokens[ $nextToken ]['content'], $this->restrictedConstants[ $tokens[ $nextToken ]['content'] ] ), $nextToken );
123123
return;
124124
}
125125

126126
if ( 1 === preg_match( '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $tokens[ $nextToken ]['content'] ) ) {
127127
// The construct is using custom constant, which needs manula inspection.
128-
$phpcsFile->addWarning( sprintf( 'File inclusion using custom constant (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
128+
$phpcsFile->addWarning( sprintf( 'File inclusion using custom constant (`%s`). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
129129
return;
130130
}
131131

132132
if ( 0 === strpos( $tokens[ $nextToken ]['content'], '$' ) ) {
133-
$phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
133+
$phpcsFile->addWarning( sprintf( 'File inclusion using variable (`%s`). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
134134
return;
135135
}
136136

@@ -141,14 +141,14 @@ public function process( File $phpcsFile, $stackPtr ) {
141141

142142
$nextNextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextToken + 1 ), null, true, null, true );
143143
if ( T_OPEN_PARENTHESIS === $tokens[ $nextNextToken ]['code'] ) {
144-
$phpcsFile->addWarning( sprintf( 'File inclusion using custom function ( %s() ). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
144+
$phpcsFile->addWarning( sprintf( 'File inclusion using custom function ( `%s()` ). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
145145
return;
146146
}
147147

148-
$phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'IncludingFile' );
148+
$phpcsFile->addError( 'Absolute include path must be used. Use `get_template_directory()`, `get_stylesheet_directory()` or `plugin_dir_path()`.', $nextToken, 'IncludingFile' );
149149
return;
150150
} else {
151-
$phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'IncludingFile' );
151+
$phpcsFile->addError( 'Absolute include path must be used. Use `get_template_directory()`, `get_stylesheet_directory()` or `plugin_dir_path()`.', $nextToken, 'IncludingFile' );
152152
return;
153153
}// End if().
154154

WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function findDirectFunctionCalls( $stackPtr ) {
190190
$next = $phpcsFile->findNext( Tokens::$functionNameTokens, $startNext, $closeBracket, false, null, true );
191191
while ( $next ) {
192192
if ( true === in_array( $tokens[ $next ]['content'], $this->catch[ $functionName ], true ) ) {
193-
$phpcsFile->addError( sprintf( "%s's return type must be checked before calling %s using that value", $tokens[ $next ]['content'], $functionName ), $next, 'CheckReturnValue' );
193+
$phpcsFile->addError( sprintf( "`%s`'s return type must be checked before calling `%s` using that value", $tokens[ $next ]['content'], $functionName ), $next, 'CheckReturnValue' );
194194
}
195195
$next = $phpcsFile->findNext( Tokens::$functionNameTokens, ( $next + 1 ), $closeBracket, false, null, true );
196196
}
@@ -299,7 +299,7 @@ public function findNonCheckedVariables( $stackPtr ) {
299299
if ( true === in_array( $tokens[ $nextFunctionCallWithVariable ]['code'], array_merge( Tokens::$functionNameTokens, $notFunctionsCallee ), true )
300300
&& $tokens[ $nextFunctionCallWithVariable ]['content'] === $callee
301301
) {
302-
$phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $nextFunctionCallWithVariable, 'CheckReturnValue' );
302+
$phpcsFile->addError( sprintf( 'Type of `%s` must be checked before calling `%s()` using that variable', $variableName, $callee ), $nextFunctionCallWithVariable, 'CheckReturnValue' );
303303
return;
304304
}
305305

@@ -308,7 +308,7 @@ public function findNonCheckedVariables( $stackPtr ) {
308308
if ( true === in_array( $tokens[ $next ]['code'], Tokens::$functionNameTokens, true )
309309
&& $tokens[ $next ]['content'] === $callee
310310
) {
311-
$phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $next, 'CheckReturnValue' );
311+
$phpcsFile->addError( sprintf( 'Type of `%s` must be checked before calling `%s()` using that variable', $variableName, $callee ), $next, 'CheckReturnValue' );
312312
return;
313313
}
314314
}

WordPressVIPMinimum/Sniffs/JS/HTMLExecutingFunctionsSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function process( File $phpcsFile, $stackPtr ) {
8181
while ( $nextToken < $parenthesis_closer ) {
8282
$nextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextToken + 1 ), null, true, null, true );
8383
if ( T_STRING === $tokens[ $nextToken ]['code'] ) {
84-
$phpcsFile->addWarning( sprintf( 'Any HTML passed to %s gets executed. Make sure it\'s properly escaped.', $tokens[ $stackPtr ]['content'] ), $stackPtr, $tokens[ $stackPtr ]['content'] );
84+
$phpcsFile->addWarning( sprintf( 'Any HTML passed to `%s` gets executed. Make sure it\'s properly escaped.', $tokens[ $stackPtr ]['content'] ), $stackPtr, $tokens[ $stackPtr ]['content'] );
8585
return;
8686
}
8787
}

WordPressVIPMinimum/Sniffs/JS/InnerHTMLSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function process( File $phpcsFile, $stackPtr ) {
8484
}
8585

8686
if ( true === $foundVariable ) {
87-
$phpcsFile->addWarning( sprintf( 'Any HTML passed to %s gets executed. Consider using .textContent or make sure that used variables are properly escaped.', $tokens[ $stackPtr ]['content'] ), $stackPtr, $tokens[ $stackPtr ]['content'] );
87+
$phpcsFile->addWarning( sprintf( 'Any HTML passed to `%s` gets executed. Consider using `.textContent` or make sure that used variables are properly escaped.', $tokens[ $stackPtr ]['content'] ), $stackPtr, $tokens[ $stackPtr ]['content'] );
8888
}
8989

9090
}//end process()

0 commit comments

Comments
 (0)