-
-
Notifications
You must be signed in to change notification settings - Fork 89
Open
Labels
@AntoineRoue
Description
Describe the bug
If I use Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast rule with this kind of array below, then the first array will be treated as a multi-line array, and this rule will expect a comma between arrays end tokens.
Code sample
- Test code:
$a = [[ 1, 2, ]];
- With
Squiz.Arrays.ArrayDeclaration.NoCommaAfterLastrule, this code is expected:
$a = [[ 1, 2, ],];
Ruleset
<?xml version="1.0"?> <ruleset name="My Custom Standard"> <rule ref="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast"/> </ruleset>
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.phpwith the test code above. - Run
phpcs test.phporphpcbf test.php - See that a comma is expected line 4, between both arrays end tokens.
PHPCS output :ERROR | [x] Comma required after last value in array declaration
Expected behavior
The first array should not be detected as multi-line.
Versions (please complete the following information)
| Operating System | Ubuntu 24 with WSL 2 with Windows 11 |
| PHP version | 8.3 |
| PHP_CodeSniffer version | 4.0.0 |
| Standard | Squiz |
| Install type | Composer (local) |
Addtitional information
In the code, the condition deciding if an array is single or multi-line is at the end of ArrayDeclarationSniff::process:
if ($tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line']) {
Please confirm
- I have searched the issue list and am not opening a duplicate issue.
- I have read the Contribution Guidelines and this is not a support question.
- I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- I have verified the issue still exists in the
4.xbranch of PHP_CodeSniffer.