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 not detecting some arrays with multiple arguments on the same line #2812

Merged
merged 2 commits into from
Apr 7, 2020
Merged

Conversation

grongor
Copy link
Contributor

@grongor grongor commented Jan 10, 2020

No description provided.

$valuePointer = $value['value'];

if ($tokens[$valuePointer]['line'] === $tokens[$stackPtr]['line']) {
$error = 'The first value in a multi-value array must be on a new line';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the code

$a = array($b, $c, $d,
$e);

Will return three times the same error ?
One time for the value $b, one time for $c and one time for $d.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add this code, I only moved it to the more appropriate position. And no, this code deals only with the first element of the array. And in general, afaik, yes - each misplaced element gets its own error. However, I'm not sure as I really didn't focus on that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I try my example, and got the error multiple times.

The check $previous === false should be added.

The best should be grouping the two checks for 'Each value in a multi-line array must be on a new line' and 'The first value in a multi-value array must be on a new line'. See next comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch with that example. I took inspiration in your next comment but fixed it a little differently. Anyway, it's now simpler and works better :)

@grongor
Copy link
Contributor Author

grongor commented Mar 16, 2020

... so, does someone want to merge this, or...?

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Mar 16, 2020

It's just a question of time.

@gsherwood will take a look when he'll have time.

ATM there are conflicts.

@grongor
Copy link
Contributor Author

grongor commented Mar 16, 2020

Yeah, I don't want to keep fixing conflicts ... please let me know when you are ready for this and I'll look into the conflict. Thanks.

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Mar 16, 2020

You can close your PR then because I don't think you will be merge that way.
Since maintainers does not have a lot of time, nobody will look at your PR if it's not RTM.
Maybe @jrfnl can help you.

@grongor
Copy link
Contributor Author

grongor commented Mar 16, 2020

Fixed it. Please make sure it gets merged this time - it's a bug fix, and it was 3 months already...

As for:

You can close your PR then because I don't think you will be merge that way.

I was very close to doing so just because you wrote that. I'm not sure that you understand how frustrating it is to have valuable time wasted, and then have it thrown at you like this.

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Mar 16, 2020

Fixed it. Please make sure it gets merged this time - it's a bug fix, and it was 3 months already...

As for:

You can close your PR then because I don't think you will be merge that way.

I was very close to doing so just because you wrote that. I'm not sure that you understand how frustrating it is to have valuable time wasted, and then have it thrown at you like this.

Do you know that I'm not a maintainer ?

And I have at least 3 PR waiting for 3 months or more on this project. I understand the situation.

I just said that you should make your PR RTM at any time and ping the good person if you want to increase the chance to be merged and decrease the leadtime. Complaining and asking to hurry without pinging the maintainers is inefficient.

@grongor
Copy link
Contributor Author

grongor commented Mar 16, 2020

I assumed you are maintainer/someone close, as people who aren't usually don't do code reviews.

I don't think that pinging someone is a good strategy - this is how you overload someone's inbox if they even have the notifications turned on.

@jrfnl
Copy link
Contributor

jrfnl commented Mar 16, 2020

I assumed you are maintainer/someone close, as people who aren't usually don't do code reviews.

Just so you know: People interested in a certain fix often also do code reviews, even when they are not otherwise involved in the project.

Same like @VincentLanglet I'm not a maintainer of this repo either, though I contribute frequently.

Reason why I've not looked at this PR is simple: the Squiz.Arrays.ArrayDeclaration sniff is broken in a lot of ways and this is a known issue (and has been for years). The intention was to split it at some point, but that never got very far, aside from the Generic.Arrays.ArrayIndent sniff.

For the standards I'm involved with, we've moved to our own Array sniffs and I'm working on making those even better and more easily available for other people via the NormalizedArrays standard in PHPCSExtra.

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Mar 16, 2020

in PHPCSExtra.

Whoah ! Just discovered this !
What are the reason behind this repository instead of adding the sniff to PHPCS ?

@grongor
Copy link
Contributor Author

grongor commented Mar 16, 2020

@jrfnl Thank you for the information. I tried to maintain "backwards compatiblity", thats why I decided to fix the sniff instead just creating a new one ...

And yeah, I also had no idea this other repo exists :D I mainly focus on sniffs at https://github.com/slevomat/coding-standard - they have thousand times more better testing enviroment, useful helpers, etc...

So ok, I'll just stop using this sniff a migrate the functionality I need somewhere else (or maybe use yours, I'll check it out later :) )

Thanks for the time.

@VincentLanglet I bet one of the reasons is that it takes forever to merge anything here :D I also personally think that sniffs shouldn't be part of this repo at all.

@jrfnl
Copy link
Contributor

jrfnl commented Mar 16, 2020

@grongor @VincentLanglet I'm hoping to finish the initial set of sniffs for NormalizedArrays over the next few weeks. It should be complete when I tag version 1.0 of PHPCSExtra.

@jrfnl
Copy link
Contributor

jrfnl commented Mar 16, 2020

What are the reason behind this repository instead of adding the sniff to PHPCS ?

More than anything, most of those sniffs use PHPCSUtils, the extensive utility function library which was pulled here as #2456 and never merged.
PHPCSUtils provides a set of utility functions for sniff authors, as well as improved versions of the existing utility functions in PHPCS itself. Extensive documentation is available here: http://phpcsutils.com/

As #2456 didn't get merged, I see no point in duplicating that work in individual sniffs and pulling them here, so that's why I'm publishing new sniffs in PHPCSExtra now.

@VincentLanglet
Copy link
Contributor

I understand. @jrfnl

I worked on some Sniff.
#2796
#2795
#2759
I think they will be useless thanks to your repository.

And maybe it'll offer a great way to split PHPCS and his sniff into two repositories.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Mar 16, 2020
@gsherwood gsherwood added this to the 3.5.5 milestone Mar 16, 2020
@gsherwood
Copy link
Member

... so, does someone want to merge this, or...?

Sorry. I get a lot of PRs I need to look through and this one is still sitting in the list.

Given this is a bug fix, it's often better to include a description of what the problem is, along with sample code, inside the PR description. This makes triage a lot easier and may have helped me tag this one as a bug a lot sooner (I try and get to bugs before features).

Thanks for the PR though. I haven't tested it out yet, but I've got it down for the next release.

@gsherwood
Copy link
Member

I worked on some Sniff.
#2796
#2795
#2759

The Squiz array sniff is down for me to tackle in 4.0: #582

So I've been planning to look at your sniffs as part of that larger project.

@grongor
Copy link
Contributor Author

grongor commented Mar 16, 2020

@gsherwood I though that example in the tests is enough - I'll write proper description next time ;-) Thank you for your time.

@gsherwood
Copy link
Member

I though that example in the tests is enough

It was absolutely enough for me to confirm this as a bug, but I was obviously busy when this got submitted and triaged it as "look at later" because the problem wasn't right in my face.

No problem though - you've done the hard work, I just missed it.

@gsherwood gsherwood changed the title Fix multi line array new lines detection for multi line values Squiz.Arrays.ArrayDeclaration not detecting some arrays with multiple arguments on the same line Apr 7, 2020
gsherwood added a commit that referenced this pull request Apr 7, 2020
@gsherwood gsherwood merged commit 8b96c3f into squizlabs:master Apr 7, 2020
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Apr 7, 2020
@gsherwood
Copy link
Member

Thanks a lot for the fix and sorry it took so long to merge. It will be in 3.5.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

None yet

5 participants