VIP-Coding-Standards
VIP-Coding-Standards copied to clipboard
NoPagingSniff: False negative when there is no comma after the parameter
Bug Description
There's a false negative when there's no comma after a single item array. For example, this will flag as expected:
$args = array(
'nopaging' => true, // Bad.
);
However, this won't:
$args = array(
'nopaging' => true // Bad.
);
Minimal Code Snippet
This should flag as an error:
$args = array( 'nopaging' => true );
Error Code
WordPressVIPMinimum.Performance.NoPaging.nopaging_nopaging
Environment
Use php -v and composer show to get versions.
| Question | Answer |
|---|---|
| PHP version | 7.4.27 |
| PHP_CodeSniffer version | 3.6.2 |
| VIPCS version | 2.3.3 |
Tested Against master branch?
- [x] I have verified the issue still exists in the
masterbranch of VIPCS. - [x] I have verified the issue still exists in the
developbranch of VIPCS.
@jrfnl Is this expected of the AbstractArrayAssignmentRestrictionsSniff?
This seems like an upstream issue. Doesn't seem to be fixed with WPCS develop (pre-3.0) branch.
The abstract class is tested with https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/WordPress/Tests/DB/SlowDBQueryUnitTest.inc and https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/WordPress/Tests/WP/PostsPerPageUnitTest.inc and neither of those have an array key and value without a trailing comma. cc @jrfnl
I agree, this should be reported upstream.
Also note that the AbstractArrayAssignmentRestrictionsSniff class is one I've barely ever touched (original was created before my time) as the premise of that sniff is iffy to say the least, so it's an abstract which is likely to have quite a few more flaws.
Closing in favour of https://github.com/WordPress/WordPress-Coding-Standards/issues/2211.