Skip to content

Commit

Permalink
Squiz/MemberVarSpacing: bug fix - don't remove blank attribute lines
Browse files Browse the repository at this point in the history
While blank lines between the docblock and the property declaration should be removed, blank lines _within_ an attribute should be ignored as that's for a sniff dealing with attribute spacing to deal with and is outside of the scope of this sniff.

Fixed now.

Includes updated test.
  • Loading branch information
jrfnl committed Feb 21, 2025
1 parent b883123 commit 3239bbd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)

// Check for blank lines between the docblock/comment and the property declaration.
for ($i = ($start + 1); $i < $startOfStatement; $i++) {
if (isset($tokens[$i]['attribute_closer']) === true) {
$i = $tokens[$i]['attribute_closer'];
continue;
}

if ($tokens[$i]['column'] !== 1
|| $tokens[$i]['code'] !== T_WHITESPACE
|| $tokens[$i]['line'] === $tokens[($i + 1)]['line']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ class MultipleBlankLinesInPreAmble {
#[MyAttribute]


#[MyOtherAttribute]
#[

BlankLinesWithinAnAttributeShouldBeLeftAlone

]

public $prop;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ class MultipleBlankLinesInPreAmble {
* Docblock.
*/
#[MyAttribute]
#[MyOtherAttribute]
#[

BlankLinesWithinAnAttributeShouldBeLeftAlone

]
public $prop;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public function getErrorList($testFile='')
384 => 1,
394 => 1,
396 => 1,
399 => 1,
408 => 1,
411 => 1,
403 => 1,
412 => 1,
415 => 1,
416 => 1,
];

default:
Expand Down

0 comments on commit 3239bbd

Please sign in to comment.