-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
Spacing of : for return declaration when including an argument #1420
Comments
For projects which use return types a lot, this can be annoying. Here's SatisPress for instance: Adding the space before the |
The fixer for this also seems slightly off. With test lines of: function returntype1(): string {} // Ok.
function returntype2( $input ): string {} // Ok.
function returntype3( $input ) : string {} // Ok.
function returntype4( string $input ): string {} // Ok.
function returntype5( string $input ) : string {} // Ok. ... the function returntype1(): string {} // Ok.
function returntype2( $input ): string {} // Ok.
function returntype3( $input ) : string {} // Ok.
function returntype4( string $input ): string {} // Ok.
function returntype5( string $input ) : string {} // Ok. for it just to complain about the violations and not about the output as well. |
The relevant part seems to be here: Adding: && T_COLON !== $this->tokens[ ( $parenthesisCloser + 1 ) ]['code'] to the condition seems to work (including for the fixer), but I suspect that this should also be accompanied by a related condition that this is part of a |
@GaryJones I think this should be included in the discussion in #1101 instead of being a separate issue. I have a local WIP branch to address #1101, but want to get 1.0.0 out of the door before getting back to it. |
fwiw, from core's best practices handbook
|
@withinboredom Ah, thank you - I think that was one of the newer additions which I forgot had been added. @jrfnl Would it be possible to get this bug fixed, before 1.0.0? Is my code above sufficient? |
I can't remember this handbook change being made ? Who changed this when ? And why wasn't an issue opened at the time ? (or is it so long ago, I don't even remember having seen it before ?) Oh dear... a search yielded issue #547 which I believe this issue should be considered a duplicate of.
I haven't got time over the next few days to work on the sniffs for #1101 and I don't think this should be haphazardly fixed in a sniff in which it doesn't belong in the first place. The only quick "fix" I can think of short term, is removing the functions related tokens from that sniff, but I'm not keen to do that while there is no replacement yet. |
I'd disagree. Any bug fix, even if not ideal for the long-term, would be better for the 1.0.0 release, which is arguably our first LTS-like release. Sure, #1101 may well remove it, but in the meantime, the quick fix is preferable IMO. My question was whether the above code looks sufficient, or whether there are test cases I can add that I can work with to narrow down when the |
As I said above, I won't have time to look at this before the release. If someone else sends in a PR, I'll try and review it in time to include it. |
When the next token after a parenthesis is a colon, AND there's a curly brace at some point after it, AND the next curly brace has a `scope_condition` that means it relates to a function, then we're dealing with a colon that is being used for a return type declaration, and therefore it should NOT be flagged. Fixes #1420.
When the next token after a parenthesis is a colon, AND the parenthesis has a `parenthesis_owner` that means it relates to a function, then we're dealing with a colon that is being used for a return type declaration, and therefore it should NOT be flagged. Fixes #1420.
When the next token after a parenthesis is a colon, AND the parenthesis has a `parenthesis_owner` that means it relates to a function or closure, then we're dealing with a colon that is being used for a return type declaration, and therefore it should NOT be flagged. Fixes #1420.
When the next token after a parenthesis is a colon, AND the parenthesis has a `parenthesis_owner` that means it relates to a function or closure, then we're dealing with a colon that is being used for a return type declaration, and therefore it should NOT be flagged. Fixes #1420.
Related to #764.
When a function has a return declaration AND at least one parameter, then a warning is thrown unless there is a space before the
:
. My understanding is that WPCS doesn't define whether a space should be included here or not. The rest of the PHP world doesn't include a space, and WPCS ONLY flags the lack of space when a parameter is present.Example:
:
, no warning.:
, no warning.Here are the warnings:
The general nature of the warning means it can't easily be excluded - either
phpcs:disable
andphpcs:enable
lines need to be added, or the whole check needs to be severity0
, which then means other instances of this whitespace issue would not be reported.The text was updated successfully, but these errors were encountered: