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

Can't satisfy Squiz.Arrays.ArrayDeclaration.ValueNoNewline with callable value #3112

Closed
simPod opened this issue Sep 11, 2020 · 6 comments
Closed
Milestone

Comments

@simPod
Copy link

simPod commented Sep 11, 2020

Describe the bug
Can't satisfy sniff when callable is within multiline array

Code sample

$a = [
    static function (): void {
    },
];

Each value in a multi-line array must be on a new line

The value is on a new line.

This can't be done either because of Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore

$a = [
    static function (): void {},
];

Closing brace must be on a line by itself

Versions (please complete the following information):

  • OS: [MacOS 10.15]
  • PHP: [e.g., 7.2, 7.4]
  • PHPCS: [e.g., 3.5.5, master]
@morozov
Copy link
Contributor

morozov commented Sep 15, 2020

This should be fixed by #3061.

@simPod
Copy link
Author

simPod commented Sep 24, 2020

Tried with dev-master but the issue seems to still exist.

@gsherwood
Copy link
Member

Tried with master and can confirm there error no longer appears.

Test file:

$ cat temp.php
<?php
$a = [
    static function (): void {
    },
];

PHPCS 3.5.6:

$ phpcs --version
PHP_CodeSniffer version 3.5.6 (stable) by Squiz (http://www.squiz.net)

$ phpcs temp.php --standard=Squiz

FILE: /Users/gsherwood/Projects/PHP_CodeSniffer/temp.php
------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
------------------------------------------------------------------------------
 1 | ERROR | [ ] Missing file doc comment
 3 | ERROR | [x] The first value in a multi-value array must be on a new line
 4 | ERROR | [x] Expected 1 blank line before closing function brace; 0 found
------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------

Time: 61ms; Memory: 8MB

Master branch:

$ php bin/phpcs --version
PHP_CodeSniffer version 3.5.7 (stable) by Squiz (http://www.squiz.net)

$ php bin/phpcs temp.php --standard=Squiz

FILE: /Users/gsherwood/Projects/PHP_CodeSniffer/temp.php
------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
------------------------------------------------------------------------------
 1 | ERROR | [ ] Missing file doc comment
 4 | ERROR | [x] Expected 1 blank line before closing function brace; 0 found
------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------

Time: 142ms; Memory: 8MB

@simPod What are you seeing?

@simPod
Copy link
Author

simPod commented Sep 24, 2020

I see, just checked. Try this:

yield [
    static fn () : string => '',
];

yield [
    static function () : string {
        return '';
    },
];

arrow function fails

gsherwood added a commit that referenced this issue Sep 24, 2020
Sniff wasn't ignore static arrow functions, or fixing the indent correctly when it actually was incorrect
gsherwood added a commit that referenced this issue Sep 24, 2020
Sniff wasn't ignore static arrow functions, or fixing the indent correctly when it actually was incorrect
@gsherwood
Copy link
Member

@simPod I've pushed an additional fix for the arrow function support. Are you able to try again?

@simPod
Copy link
Author

simPod commented Sep 25, 2020

Wrks, thanks a lot!

@simPod simPod closed this as completed Sep 25, 2020
@gsherwood gsherwood added this to the 3.5.7 milestone Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants