coding-standards icon indicating copy to clipboard operation
coding-standards copied to clipboard

Error on line with comment

Open solracsf opened this issue 7 years ago • 1 comments

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.

solracsf avatar Jan 31 '18 15:01 solracsf

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

mbabker avatar Jan 31 '18 19:01 mbabker