Skip to content

Commit 3239bbd

Browse files
committed
Squiz/MemberVarSpacing: bug fix - don't remove blank attribute lines
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.
1 parent b883123 commit 3239bbd

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
9494

9595
// Check for blank lines between the docblock/comment and the property declaration.
9696
for ($i = ($start + 1); $i < $startOfStatement; $i++) {
97+
if (isset($tokens[$i]['attribute_closer']) === true) {
98+
$i = $tokens[$i]['attribute_closer'];
99+
continue;
100+
}
101+
97102
if ($tokens[$i]['column'] !== 1
98103
|| $tokens[$i]['code'] !== T_WHITESPACE
99104
|| $tokens[$i]['line'] === $tokens[($i + 1)]['line']

src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.1.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,11 @@ class MultipleBlankLinesInPreAmble {
395395
#[MyAttribute]
396396

397397

398-
#[MyOtherAttribute]
398+
#[
399+
400+
BlankLinesWithinAnAttributeShouldBeLeftAlone
401+
402+
]
399403

400404
public $prop;
401405
}

src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.1.inc.fixed

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,11 @@ class MultipleBlankLinesInPreAmble {
382382
* Docblock.
383383
*/
384384
#[MyAttribute]
385-
#[MyOtherAttribute]
385+
#[
386+
387+
BlankLinesWithinAnAttributeShouldBeLeftAlone
388+
389+
]
386390
public $prop;
387391
}
388392

src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public function getErrorList($testFile='')
7979
384 => 1,
8080
394 => 1,
8181
396 => 1,
82-
399 => 1,
83-
408 => 1,
84-
411 => 1,
82+
403 => 1,
8583
412 => 1,
84+
415 => 1,
85+
416 => 1,
8686
];
8787

8888
default:

0 commit comments

Comments
 (0)