Permalink
Browse files

Squiz SuperfluousWhitespaceSniff no longer throws errors for CSS file…

…s with no newline at the end and allows a single newline at the end of JS and CSS files
  • Loading branch information...
1 parent 08b3708 commit 391c36bbbbf4cbd51f9f5014a61a753368c417b4 @gsherwood gsherwood committed Jan 31, 2013
@@ -130,21 +130,16 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
// and the second last token is always the last piece of content in
// the file. If the second last token is whitespace, there was
// whitespace at the end of the file.
- if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) {
- return;
- }
+ $stackPtr--;
} else if ($phpcsFile->tokenizerType === 'CSS') {
// The last two tokens are always the close tag and whitespace
// inserted when tokenizsed and the third last token is always the
// last piece of content in the file. If the third last token is
// whitespace, there was whitespace at the end of the file.
- if ($tokens[($stackPtr - 3)]['code'] !== T_WHITESPACE) {
- return;
- }
-
- // Adjust the pointer to give the correct line number for the error.
$stackPtr -= 2;
- } else {
+ }
+
+ if ($phpcsFile->tokenizerType === 'PHP') {
if (isset($tokens[($stackPtr + 1)]) === false) {
// The close PHP token is the last in the file.
return;
@@ -164,6 +159,20 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}
}
+ } else {
+ // The pointer is now looking at the last content in the file and
+ // not the fake PHP end tag the tokenizer inserted.
+ if ($tokens[$stackPtr]['code'] !== T_WHITESPACE) {
+ return;
+ }
+
+ // Allow a single newline at the end of the last line in the file.
+ if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE
+ && $tokens[$stackPtr]['content'] === $phpcsFile->eolChar
+ ) {
+ return;
+ }
+
}
$phpcsFile->addError('Additional whitespace found at end of file', $stackPtr, 'EndFile');
@@ -0,0 +1,3 @@
+.HelpWidgetType-new-bug-title {
+ float: left;
+}
@@ -0,0 +1,3 @@
+.HelpWidgetType-new-bug-title {
+ float: left;
+}
@@ -58,7 +58,7 @@ public function getErrorList($testFile='SuperfluousWhitespaceUnitTest.inc')
48 => 1,
);
break;
- case 'SuperfluousWhitespaceUnitTest.js':
+ case 'SuperfluousWhitespaceUnitTest.1.js':
return array(
1 => 1,
3 => 1,
@@ -71,7 +71,7 @@ public function getErrorList($testFile='SuperfluousWhitespaceUnitTest.inc')
47 => 1,
);
break;
- case 'SuperfluousWhitespaceUnitTest.css':
+ case 'SuperfluousWhitespaceUnitTest.1.css':
return array(
1 => 1,
8 => 1,
@@ -675,14 +675,8 @@ public function tokenizeString($string, $eolChar='\n')
}
}//end foreach
- // Trim the last newline off the end of the buffer before
- // adding it's contents to the token stack.
- // This is so we don't count the very final newline of a file.
- $buffer = substr($buffer, 0, -1);
-
if (empty($buffer) === false) {
- // Buffer contains whitespace from the end of the file, and not
- // just the final newline.
+ // Buffer contains whitespace from the end of the file.
$tokens[] = array(
'code' => T_WHITESPACE,
'type' => 'T_WHITESPACE',
@@ -699,7 +693,7 @@ public function tokenizeString($string, $eolChar='\n')
'code' => T_CLOSE_TAG,
'type' => 'T_CLOSE_TAG',
'content' => '',
- );
+ );
/*
Now that we have done some basic tokenizing, we need to

0 comments on commit 391c36b

Please sign in to comment.