Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned doesn't work inside match #475

Closed
3 tasks done
LastDragon-ru opened this issue Apr 29, 2024 · 3 comments · Fixed by #502
Closed
3 tasks done

Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned doesn't work inside match #475

LastDragon-ru opened this issue Apr 29, 2024 · 3 comments · Fixed by #502

Comments

@LastDragon-ru
Copy link

Describe the bug

Calculation of the align seems incorrect inside match.

Code sample

<?php declare(strict_types = 1);

// Ok
$a = [
    'a'  => 'a',
    'aa' => 'aa',
];

// Nope
$b = match (true) {
    true => [
        'a'  => 'a',
        'aa' => 'aa',
    ],
};

$c = match (true) {
    true => implode(', ', [
        'a'  => 'a',
        'aa' => 'aa',
    ]),
};

$c = match (true) {
    true => implode(
        ', ',
        [
            'a'  => 'a',
            'aa' => 'aa',
        ],
    ),
};

Custom ruleset

<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor-bin/phpcs/vendor/squizlabs/php_codesniffer/phpcs.xsd">
    <rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned"/>
</ruleset>

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed
-------------------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 6 LINES
-------------------------------------------------------------------------------------------
 12 | ERROR | [x] Array double arrow not aligned correctly; expected 1 space but found 2
 13 | ERROR | [x] Array double arrow not aligned correctly; expected 4 spaces but found 13
 19 | ERROR | [x] Array double arrow not aligned correctly; expected 1 space but found 13
 20 | ERROR | [x] Array double arrow not aligned correctly; expected 1 space but found 13
 28 | ERROR | [x] Array double arrow not aligned correctly; expected 1 space but found 17
 29 | ERROR | [x] Array double arrow not aligned correctly; expected 1 space but found 17
-------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------

Expected behavior

No error.

Versions (please complete the following information)

Operating System Windows 10
PHP version 8.3
PHP_CodeSniffer version 3.9.2
Standard custom
Install type composer

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • 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.
@jrfnl
Copy link
Member

jrfnl commented May 19, 2024

@LastDragon-ru I've just tested myself and it looks like PR #502 should also fix this issue. Testing appreciated.

@LastDragon-ru
Copy link
Author

I've tested it my project and seems all good :) Thanks.

@jrfnl
Copy link
Member

jrfnl commented May 21, 2024

@LastDragon-ru Thanks for testing!

@jrfnl jrfnl changed the title Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned doens't work inside match Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned doesn't work inside match May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants