Skip to content

Commit 006db7d

Browse files
committed
Fixed bug #1702 : Generic.WhiteSpaceDisallowSpaceIndent fixer bug when line only contains superfluous whitespace
1 parent 1477525 commit 006db7d

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
4848
- Fixed bug #1681 : Huge arrays are super slow to scan with Squiz.Arrays.ArrayDeclaration sniff
4949
- Fixed bug #1694 : Squiz.Arrays.ArrayBracketSpacing is removing some comments during fixing
5050
-- Thanks to Juliette Reinders Folmer for the patch
51+
- Fixed bug #1702 : Generic.WhiteSpaceDisallowSpaceIndent fixer bug when line only contains superfluous whitespace
5152
</notes>
5253
<contents>
5354
<dir name="/">

src/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ public function process(File $phpcsFile, $stackPtr)
9999
if (isset($matches[2]) === true) {
100100
$nonWhitespace = $matches[2];
101101
}
102+
} else if (isset($tokens[($i + 1)]) === true
103+
&& $tokens[$i]['line'] < $tokens[($i + 1)]['line']
104+
) {
105+
// There is no content after this whitespace except for a newline.
106+
$content = rtrim($content, "\r\n");
107+
$nonWhitespace = $phpcsFile->eolChar;
102108
}
103109

104110
$hasSpaces = strpos($content, ' ');
@@ -116,7 +122,7 @@ public function process(File $phpcsFile, $stackPtr)
116122
}
117123

118124
if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE && $content === ' ') {
119-
// Ignore file/class-level DocBlock, especially for recording metrics.
125+
// Ignore file/class-level docblocks, especially for recording metrics.
120126
continue;
121127
}
122128

src/Standards/Generic/Tests/WhiteSpace/DisallowSpaceIndentUnitTest.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,15 @@ $x = 1;
6868
echo 'And another one.'
6969
echo 'And another one.'
7070
echo 'And another one.'
71+
72+
// Spaces after comment.
73+
74+
$x = 1;
75+
76+
// Mixed tabs and spaces after comment.
77+
78+
$x = 1;
79+
80+
// Mixed spaces and tabs after comment.
81+
82+
$x = 1;

src/Standards/Generic/Tests/WhiteSpace/DisallowSpaceIndentUnitTest.inc.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,15 @@ $x = 1;
6868
echo 'And another one.'
6969
echo 'And another one.'
7070
echo 'And another one.'
71+
72+
// Spaces after comment.
73+
74+
$x = 1;
75+
76+
// Mixed tabs and spaces after comment.
77+
78+
$x = 1;
79+
80+
// Mixed spaces and tabs after comment.
81+
82+
$x = 1;

src/Standards/Generic/Tests/WhiteSpace/DisallowSpaceIndentUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public function getErrorList($testFile='DisallowSpaceIndentUnitTest.inc')
4949
68 => 1,
5050
69 => 1,
5151
70 => 1,
52+
73 => 1,
53+
77 => 1,
54+
81 => 1,
5255
);
5356
break;
5457
case 'DisallowSpaceIndentUnitTest.js':

0 commit comments

Comments
 (0)