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.ValueNoNewline false positive with static fn #559

Open
3 of 4 tasks
simPod opened this issue Jul 16, 2024 · 3 comments
Open
3 of 4 tasks

Comments

@simPod
Copy link

simPod commented Jul 16, 2024

Describe the bug

Squiz.Arrays.ArrayDeclaration.ValueNoNewline triggers false positive at static fn.

Code sample

return [
    static fn (string $value): AAA => new AAA($value),
    BBB::fromString(...),
];

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
PHPCS output here

Expected behavior

No error

Versions (please complete the following information)

Operating System macos 14
PHP version 8.3
PHP_CodeSniffer version 3.10.1
Standard Squiz
Install type composer

Additional context

Add any other context about the problem here.

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.
@jrfnl
Copy link
Member

jrfnl commented Jul 16, 2024

Confirmed. Thanks for reporting this @simPod.

This looks like a similar issue to #368 which was fixed by #369 and #379, which were included in the 3.9.1 release.
I've checked and the fixes in the 3.9.1 release are not directly related to this issue. This issue can be reproduced both with PHPCS 3.9.0 as well as master.

The Squiz.Arrays.ArrayDeclaration sniff is known to be problematic and has been for years.

The problem is largely that as soon as something is excluded from that sniff, the sniff is broken. This is a design flaw in the sniff.

I've been building up a (highly configurable) NormalizedArrays standard in PHPCSExtra to replace it, but that's not complete yet. Would be lovely if I could find some time to finish that at some point.

With that in mind, I will not be working on this issue.
If someone would submit a PR with a small/simple fix for this issue, I will accept it, but other than that, this sniff is out of bounds for large fixes/rewrites as it is just not worth the time.

@LastDragon-ru
Copy link

Seems also related to this issue?

<?php declare(strict_types = 1);

class Bug {
    public static function bug(): mixed {
        return [
            'paginator' => [
                new class() {
                    public function toArray(): mixed {
                        return [];
                    }
                },
            ],
        ];
    }
}
 9 | ERROR | [x] The first value in a multi-value array must be on a new line
 9 | ERROR | [x] Each value in a multi-line array must be on a new line

@jrfnl
Copy link
Member

jrfnl commented Jul 19, 2024

@LastDragon-ru To be honest, that looks like a completely different issue to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants