-
-
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 in closures #439
Comments
Yes, this is ouch. I was just about to file the same issue. EDIT it's possible to override it in your own project configuration #417 (comment)
|
I raised this at #417 (comment) . In this case, I can only assume that @JDGrimes defaulted (or let the Squiz sniff default) to PSR-2, which does have spaces: http://www.php-fig.org/psr/psr-2/#6-closures Anonymous functions / closures tend not to be found in Core, so things like this, namespaces and other non-core goodies are something that I've raised with @DrewAPicture so that we can get it clarified in the handbooks regardless of whether WP core is using it. Drew, can this particular point be raised sooner with the Core team, so we can amend as necessary? FWIW, no-space (like WP CS JS uses) is my slight preference. The only occurrence I could see in core was in tests/phpunit/actions/closures where no-space is used twice. If this is sufficiently indicative, then a change will be needed in WPCS. |
I don't have a strong preference either way, but I tend to use the space. ("When in doubt, space it out!" 😈) But we can make |
The fact that 100% of instances have no-space in core (OK, so 2 out of 2, in tests (!)), named function declarations don't have a space, and anonymous functions in JS don't (and there being some intent to have consistency between JS and PHP), I think I'd prefer no preference to be expected for |
OK, should we release a 0.7.1 with that change? |
@JDGrimes great idea 👍 |
+1 for 0.7.1. I meant to suggest that in my previous comment. |
Thanks for the quick turnaround! |
I'm not happy with the reasoning behind this decision, as I would argue that it does not make sense at all. A named function declaration would be In a closure, what gets omitted is the name of the function, so you'd remove the You're NOT passing arguments to |
@schlessera also pointed out that PHPStorm doesn't even have the Coding Style option (yet?) to remove that space. |
Haha, apparently they consider this to be a bug in PHPStorm... Oh well, nevertheless, I maintain my arguments, it is not a call to |
@schlessera I agree, which is why I use the space. But this project doesn't control the standards that WordPress uses, we just implement sniffs for those standards. We need to be compatible with WordPress's declared standards by default, which is why this change was made. Those of us that disagree with WordPress's standards can try to get them changed. Until that happens, you can override the default in your phpcs.xml config: <rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
<properties>
...
<property name="spaces_before_closure_open_paren" value="1" />
</properties>
</rule> |
Yes, I agree with that, but in this case, WordPress does not have any standard to speak of. The two instances that @GaryJones managed to find can't possibly be considered conclusive. So, why not just ignore this until Core has made a decision? Yes, I'll consider overriding it in my projects. Thanks! |
No, those instances aren't conclusive. I would have favored turning off this check entirely by default, except that it is a part of the JavaScript standards, and a strong emphasis has been placed on parity between the PHP and JS standards in regards to whitespace. I'm still not against ignoring this check by default until it is clarified in the PHP standards. However, that will mean that everyone will need to implement a custom configuration if they want to sniff for that. @GaryJones @westonruter any thoughts? |
I think it should be ignored by default. It can be an opt-in for now, and once Core has a standard for closure formatting, we can enable the check. |
As per 24 days ago:
@DrewAPicture has taken my suggestions (raised in Docs chat) about the PHP CS listed in the Handbooks to core devs, but really, the choosing of standards for use in the community should be a separate group. They'd (core and non-core devs) decide on the standards (with strong influence from historical use in core, obviously), the standards are written up via the Docs team, given to WPCS to be programatically testable, and then core, plugin and theme authors could use them. This lack of the initial CS group is just frustrating. |
Ah, I must have missed that somehow. I don't know why I defaulted it to |
I deferred to your expert decision :-) |
Many of my Travis-tested repos just started failing due to the merge of #417. I see that WPCS now wants:
to be:
I see no mention of this in the WordPress Coding Standards. Is there a secondary guide that WPCS is using to make decisions like this? If it's a matter of opinion, I'd love to see the discussion so I can better understand why this format was chosen. I personally think
function() {
makes more, as it follows the non-closure function standard more closely, where the parens are adjacent to the function name likefunction foo() {
. If it were just a matter of opinion, I would hide it in my ruleset, though it doesn't look like this can be ignored without also affecting other control structures (please correct me if I'm wrong) covered byWordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterStructureOpen
andWordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeOpenParenthesis
.Thanks!
The text was updated successfully, but these errors were encountered: