joomla / coding-standards

Joomla Coding Standards Definition
https://developer.joomla.org/coding-standards/basic-guidelines.html
GNU General Public License v2.0
128 stars 129 forks source link

Error on line with comment #226

Open solracsf opened 6 years ago

solracsf commented 6 years ago

Test case:

<?php
catch (Exception $e) { $result = false; } // suppress exception in case of SQL error, we will print it below

This looks to be due to a conflict between the Joomla.Commenting.SingleComment and Squiz.WhiteSpace.ControlStructureSpacing sniffs.

Relevant debug code:

---START FILE CONTENT---
1|<?php
2|catch (Exception $e)
3|{
4|  $result = false;
5|
6|} // Suppress exception in case of SQL error, we will print it below
7|
--- END FILE CONTENT ---
    E: [Line 5] Blank line found at end of control structure (Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose)
    => Changeset started by PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ControlStructureSpacingSniff (line 214)
        Q: PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ControlStructureSpacingSniff (line 224) replaced token 19 (T_WHITESPACE) "\n}" => "}"
        A: PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ControlStructureSpacingSniff (line 227) replaced token 19 (T_WHITESPACE) "\n}" => "}"
    => Changeset ended: 1 changes applied
    * fixed 1 violations, starting loop 7 *
---START FILE CONTENT---
1|<?php
2|catch (Exception $e)
3|{
4|  $result = false;
5|} // Suppress exception in case of SQL error, we will print it below
6|
--- END FILE CONTENT ---
    E: [Line 5] Please consider a blank line preceding your comment. (Joomla.Commenting.SingleComment.BlankBefore)
    Joomla\Sniffs\Commenting\SingleCommentSniff (line 171) replaced token 18 (T_WHITESPACE) "\n}" => "\n\n}"
    * fixed 1 violations, starting loop 8 *
---START FILE CONTENT---
1|<?php
2|catch (Exception $e)
3|{
4|  $result = false;
5|
6|} // Suppress exception in case of SQL error, we will print it below
7|
--- END FILE CONTENT ---

I suspect the fix is detecting that the comment is on the same line as a closing token and changing the fix to put the comment on a new line, or just allowing this.

mbabker commented 6 years ago

This is by design. Our coding standard does not allow a trailing comment on a line of executable code.