Skip to content

Error on line with comment #226

@solracsf

Description

@solracsf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions