-
-
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
Ensure that the closing brace is properly aligned #1474
Comments
@david-binda That sniff only addresses the open brace. There is another sniff - which IIRC is included in WPCS - which checks the closing brace. |
Oh, it does not seem to kick-in then :) Also, I might not have expressed myself properly. I don't think there is an issue in the sniff ensuring the opening brace is the last thing on a line, just that we might be missing a complementary sniff properly handling the closing brace. |
@david-binda No worries. I'm at WC Nijmegen at the moment, but will try and look into it over the next few days. |
@david-binda Finally got round to this and you are 100% correct, there is a sniff missing here which should handle this. This was actually previously reported as part of issue #1101 - item nr 8. I'm looking into the various sniffs related to this now and will send in a PR to address this. |
Thank you for following up! |
@WordPress-Coding-Standards/wpcs-admins Open question related to this issue: what should be the fixer behaviour for empty scopes ? function wp_dashboard_empty() {} Should this be allowed as-is ? Or should this be "fixed" to: function wp_dashboard_empty() {
} |
Allowed (or even enforced) as is: having the closing brace on the same line makes it clear that it's an empty scope. |
From issue #1101:
OK, so I have (finally) run some pretty extensive tests with these sniffs. I've basically done separate WP Core fixer runs with each of these sniffs and compared the results:
Both sniffs target close braces of all constructs which PHPCS regards as scope openers. This means that the close brace of classes, interface, functions, but also all control structures, such as IMO this is a good thing as the WPCS rulesets currently appear not to check the close brace position for these other constructs either. Adding (a variation on) either of these sniffs to WPCS, would also partially address some of the remaining indentation issues we've seen in the WP Core runs, though as some of the PHP open tags for multi-line embedded PHP in WP Core are still in the wrong place, an initial auto-fixer run with such a sniff would need very careful scrutiny and I expect quite a lot of manual tinkering to get things just right. I suspect that the fixer conflicts are also related to multi-line embedded PHP, but this needs further investigation and until a solution is found for this - either by manual tinkering or by creating fixes for the upstream sniffs -, I can't create a definitive solution (PR) for this issue. @pento Want to have a look at the current results ? I can put the branches I have created online in a WP Core git fork here on GH. |
@jrfnl: I'd love to have a look. 🙂 |
@pento I've put them online for your perusal - mind: these are "dirty" branches:
|
Ran into this again this week trying to automatically start the cleanup process for a plugin. WPCS uses |
I believe that to action this issue, the analysis from comment #1474 (comment) will need to be redone with the current version of PHPCS to see if the outcomes are any better. Based on that redone analysis, a decision can then be taken to either include one of the two pre-existing sniffs or to add a sniff to PHPCSExtra which handles this in a more configurable way. |
The Kernighan opening function Brace Sniff ( Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace ) which is part of the WordPress Coding Standard on it's own does not always produce desired output when it comes to running phpcbf.
WordPress Coding Standards v1.0 was used for updating following function in WordPress:
with following result:
See https://core.trac.wordpress.org/changeset/42343/trunk/src/wp-admin/includes/noop.php for real-live example.
Imho, such a change does not really improve readability of the code. From my point of view, the desired output should be as follows:
While this is not explicitly defined in the WordPress coding standards, an example which can be found in https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#space-usage is very similar to the desired output described above:
The text was updated successfully, but these errors were encountered: