Skip to content

Commit af90533

Browse files
committed
Only modify tokens if the content changed (cleaner debug output)
1 parent daa440f commit af90533

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,27 @@ public function process(File $phpcsFile, $stackPtr)
110110
}
111111

112112
for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
113-
if (isset($tokens[($i + 1)]) === false
114-
|| $tokens[($i + 1)]['line'] > $tokens[$i]['line']
113+
if (isset($tokens[($i + 1)]) === true
114+
&& $tokens[($i + 1)]['line'] <= $tokens[$i]['line']
115115
) {
116-
// Token is the last on a line.
117-
if (isset($tokens[$i]['orig_content']) === true) {
118-
$tokenContent = $tokens[$i]['orig_content'];
119-
} else {
120-
$tokenContent = $tokens[$i]['content'];
121-
}
122-
123-
if ($tokenContent === '') {
124-
// Special case for JS/CSS close tag.
125-
continue;
126-
}
127-
128-
$newContent = rtrim($tokenContent, "\r\n");
129-
$newContent .= $eolChar;
116+
continue;
117+
}
118+
119+
// Token is the last on a line.
120+
if (isset($tokens[$i]['orig_content']) === true) {
121+
$tokenContent = $tokens[$i]['orig_content'];
122+
} else {
123+
$tokenContent = $tokens[$i]['content'];
124+
}
125+
126+
if ($tokenContent === '') {
127+
// Special case for JS/CSS close tag.
128+
continue;
129+
}
130+
131+
$newContent = rtrim($tokenContent, "\r\n");
132+
$newContent .= $eolChar;
133+
if ($tokenContent !== $newContent) {
130134
$phpcsFile->fixer->replaceToken($i, $newContent);
131135
}
132136
}//end for

0 commit comments

Comments
 (0)