Skip to content

Squiz.Arrays.ArrayDeclaration.NoComma adds invalid comma to certain match statements since 3.10.1 #747

Open
@janedbal

Description

@janedbal

Describe the bug

Mentioned fixable sniff breaks the PHP code as follows:

Code sample

match ($foo) {
    'a' => [
        'x' => 0,
        'y' => 0,
    ],
    default => 0
};

Custom ruleset

<?xml version="1.0"?>
<ruleset>
    <rule ref="Squiz.Arrays.ArrayDeclaration.NoComma"/>
</ruleset>

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above
  2. Create phpcs.xml with the custom ruleset above
  3. Run phpcbf test.php
  4. See fix applied
match ($foo) {
    'a' => [
        'x' => 0,
        'y' => 0,
    ,],
    default => 0
};

Expected behavior

No file changes.

Versions

Operating System ubuntu
PHP version PHP 8.3.13
PHP_CodeSniffer version 3.10.1
Standard Squiz
Install type composer

Additional context

Version 3.10.0 does not contains this issue.

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 master branch of PHP_CodeSniffer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions