You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1 | ERROR | [ ] Missing file doc comment (Squiz.Commenting.FileComment.Missing)
4 | WARNING | [ ] Detected high pagination limit, `posts_per_page` is set to `999`
| | (WordPress.WP.PostsPerPage.posts_per_page_posts_per_page)
8 | WARNING | [ ] Detected high pagination limit, `posts_per_page` is set to `999
| | )` (WordPress.WP.PostsPerPage.posts_per_page_posts_per_page)
8 | ERROR | [x] Each array item in a multi-line array declaration must end in a comma (WordPress.Arrays.CommaAfterArrayItem.NoComma)
Line 4 and line 8 (the 999 lines) are both captured as a violation, though interestingly, the "value" captured for line 8 seems to be 999 ) (with a line break as well), as though it hasn't recognised the line break as being the intended end of the line/value. I suspect there's some casting to int going on where 999\n( is seen as 999, which is sufficient to make it a violation.
Example 2
From the VIPCS NoPaging sniff, which also extends WPCS's AbstractArrayAssignmentRestrictionsSniff, a test file of:
4 | ERROR | Disabling pagination is prohibited in VIP context, do not set `nopaging` to `true` ever.
| | (WordPressVIPMinimum.Performance.NoPaging.nopaging_nopaging)
...because I suspect the second value is seen as true ) (with a line break), which doesn't resolve to true (unlike the int casting from Example 1).
Testing with $args = array('nopaging=true'); and the violation is correctly captured.
Looks like this issue is a duplicate of #1505. As #1505 was closed already, I won't mark this issue as a duplicate, but leaving this comment to make sure the issues are linked.
Bug Description
Sniff classes that extend the
AbstractArrayAssignmentRestrictionsSniff
class don't capture the correct value when the array item has no trailing comma.Minimal Code Snippet
Example 1
Testing the
PostPerPage
sniff which extendsAbstractArrayAssignmentRestrictionsSniff
. With this test file:...and this command (run inside a Git clone of WPCS):
The output includes:
Line 4 and line 8 (the
999
lines) are both captured as a violation, though interestingly, the "value" captured for line 8 seems to be999 )
(with a line break as well), as though it hasn't recognised the line break as being the intended end of the line/value. I suspect there's some casting to int going on where999\n(
is seen as999
, which is sufficient to make it a violation.Example 2
From the VIPCS
NoPaging
sniff, which also extends WPCS'sAbstractArrayAssignmentRestrictionsSniff
, a test file of:...and a command of:
...only captures the first instance:
...because I suspect the second value is seen as
true )
(with a line break), which doesn't resolve to true (unlike the int casting from Example 1).Testing with
$args = array('nopaging=true');
and the violation is correctly captured.Environment
develop
Additional Context (optional)
Originally reported in Automattic/VIP-Coding-Standards#713.
Tested Against
develop
branch?develop
branch of WPCS.The text was updated successfully, but these errors were encountered: