Skip to content

Add psalm-prefixed annotations to param and return group #238

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

Merged
merged 1 commit into from
Mar 29, 2021

Conversation

simonberger
Copy link
Contributor

No description provided.

Copy link
Member

@ostrolucky ostrolucky left a comment

Choose a reason for hiding this comment

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

While we are it, we should also add phpstan- variants. Also, tests are usually needed

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

I had no idea it would be that easy 👍
Please add some tests though, so that we are sure what the result is… I supposed there will be no constraint on the order of elements inside a group but let's check. Also, it would be interesting to see what it means for alignment of types, variable names and descriptions

@simonberger
Copy link
Contributor Author

I added tests for all new annotations.

@greg0ire greg0ire requested review from ostrolucky and a team March 14, 2021 23:18
ostrolucky
ostrolucky previously approved these changes Mar 14, 2021
@greg0ire greg0ire requested a review from a team March 15, 2021 06:48
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

I think more tests are needed to take a decision

* @param int[] $foo
* @param int[] $bar
* @psalm-param array<int, string> $bar
* @phpstan-param array<int, string> $bar
Copy link
Member

@greg0ire greg0ire Mar 15, 2021

Choose a reason for hiding this comment

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

Since there are only 2 parameters here, it's impossible to tell if the @psalm- and @phpstan- annotations are last because $bar is the last parameter, or because they are @psalm- and @phpstan- annotations. Also this snippet shows that types are aligned, but variable names are not, and does not show what happens to descriptions.

Copy link
Contributor Author

@simonberger simonberger Mar 23, 2021

Choose a reason for hiding this comment

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

Entries are sorted also inside the group by description of the tool. I don't think we have to test this but I could add it. Variables aren't aligned in the group at least not beyond same annotation name. I don't know what to do about it. The phpcs + extension used here is not good documented and might have conflicting settings.
Maybe someone with more insights of the tool wanna have a look at it if this is a requirement.

Copy link
Member

Choose a reason for hiding this comment

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

Can you annotate $foo instead of $bar? That will take care of my first remark. Also, int[] is not compatible with array<int, string>, it would be less confusing to have array<int, int> or array<string, int>` here.

Regarding the second remark, I don't think it should be a requirement to have the variables and descriptions aligned, and I thought it shouldn't come as a surprise to reviewers that would approve this, but maybe what you are saying is that it would be wrong to "enforce" not aligning with a test.

Also, it looks pretty hardcoded, so there is not much hope to get it fixed quickly:

https://github.com/squizlabs/PHP_CodeSniffer/blob/2bd19c2e6edb918ab14d87f1c4b37d1f112d8f00/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php#L296

Let's drop that second remark.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@greg0ire I did the change in the test. Did you expect a correction of the param order? This did not happen and seems not to be part of the tool (or it had to be configured.

Copy link
Member

Choose a reason for hiding this comment

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

@simonberger I was unsure and wanted to see what happened, as well as other reviewers. IMO it's already fine like this.

@greg0ire
Copy link
Member

Please associate your email address with your Github account, or change the
email in your commits to an address already associated with it. If you do not
want to expose your personal email address, you may use
$userName@users.noreply.github.com, that way we can still reach you through Github.
Additionally, you will get credit for this contribution on your Github profile.

greg0ire
greg0ire previously approved these changes Mar 27, 2021
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

To be squash-merged

ostrolucky
ostrolucky previously approved these changes Mar 27, 2021
@simonberger
Copy link
Contributor Author

Yes I'll fix this. Forgot to override the git email for the fork.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@simonberger
Copy link
Contributor Author

Rebased and changed email.

@greg0ire greg0ire requested a review from a team March 27, 2021 19:25
* @param int[] $foo
* @param int[] $bar
* @param int[] $foo
* @param int[] $bar
Copy link
Member

Choose a reason for hiding this comment

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

Is it intended that parameter types are aligned regardless of the vendor prefix but the names aren't? Since we assume prefixed and non-prefixed to have the same meaning, I'd expect them to be aligned in the same way:

* @param         int[]              $foo
* @param         int[]              $bar
* @psalm-param   array<string, int> $foo
* @phpstan-param array<string, int> $foo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @morozov we discussed this here #238 (comment)
It is not possible from the phpcs package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you are interested in having this formatting I am pretty sure adding another configuration option to phpcs shouldn't be too hard. But from the structure of the code I don't want to spend time getting into it to contribute there.

Copy link
Member

Choose a reason for hiding this comment

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

Yes it's not the goal of this PR, would be a scope creep

@greg0ire greg0ire merged commit 378aa39 into doctrine:8.2.x Mar 29, 2021
@greg0ire
Copy link
Member

Thanks @simonberger !

@greg0ire
Copy link
Member

greg0ire commented Apr 2, 2021

Should this have targeted 9.0.x instead? 🤔 I'm not sure of what is considered a BC-break in this repository exactly, but this feels like it will have a big impact on the code base of projects using this standard won't it ?

@simonberger
Copy link
Contributor Author

I cannot really say much to this or even give an advice. Almost any coding standard change could be called a breaking change. It should just affect changes on new code (in most projects), but then can report issues on code the recent PR did not introduce.

@greg0ire
Copy link
Member

greg0ire commented Apr 3, 2021

I'll ask for guidance internally.

@greg0ire
Copy link
Member

greg0ire commented Apr 3, 2021

To quote @alcaeus

The stance was “if it introduces new errors that aren’t due to bug fixes, it’s a bc break”. Exceptions apply where even a bug fix may only be applied in the next major depending on impact (e.g. thousands of errors in our own projects)

I will revert this from 8.2.x and cherry-pick it on 9.0.x

@greg0ire greg0ire added this to the 9.0.0 milestone Apr 3, 2021
@beberlei
Copy link
Member

beberlei commented Apr 3, 2021

I would assume every change to the standard should get its own major, essentially leading to always just 9.0.0, 10.0.0 etc since its seldom that we have real bugs.

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

Successfully merging this pull request may close these issues.

None yet

5 participants