Closed GaryJones closed 1 year ago
I have a fix lined up for this, but this sniff will need quite some more fixes. Will pull it as part of a larger PR which also implements PHPCSUtils.
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 https://github.com/Automattic/VIP-Coding-Standards/issues/713.
Tested Against
develop
branch?develop
branch of WPCS.