Permalink
Browse files

Generic EndFileNewlineSniff now supports JS and CSS files

  • Loading branch information...
1 parent 7288953 commit c7e4be4f9b045b8f46cc36af7da3bdda9bb4b030 @gsherwood gsherwood committed Jan 31, 2013
View
20 CodeSniffer/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php
@@ -29,6 +29,18 @@ class Generic_Sniffs_Files_EndFileNewlineSniff implements PHP_CodeSniffer_Sniff
{
/**
+ * A list of tokenizers this sniff supports.
+ *
+ * @var array
+ */
+ public $supportedTokenizers = array(
+ 'PHP',
+ 'JS',
+ 'CSS',
+ );
+
+
+ /**
* Returns an array of tokens this test wants to listen for.
*
* @return array
@@ -62,10 +74,16 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens();
$stackPtr = ($phpcsFile->numTokens - 1);
+ if ($phpcsFile->tokenizerType === 'JS') {
+ $stackPtr--;
+ } else if ($phpcsFile->tokenizerType === 'CSS') {
+ $stackPtr -= 2;
+ }
+
$eolCharLen = strlen($phpcsFile->eolChar);
$lastChars = substr($tokens[$stackPtr]['content'], ($eolCharLen * -1));
if ($lastChars !== $phpcsFile->eolChar) {
- $error = 'All PHP files must end with a newline character';
+ $error = 'File must end with a newline character';
$phpcsFile->addError($error, $stackPtr, 'NotFound');
}
View
3 CodeSniffer/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.1.css
@@ -0,0 +1,3 @@
+
+#login-container {}
+
View
3 CodeSniffer/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.1.js
@@ -0,0 +1,3 @@
+
+alert('hi);
+
View
2 CodeSniffer/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.2.css
@@ -0,0 +1,2 @@
+
+#login-container {}
View
2 CodeSniffer/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.2.js
@@ -0,0 +1,2 @@
+
+alert('hi);
View
2 CodeSniffer/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.3.css
@@ -0,0 +1,2 @@
+
+#login-container {}
View
2 CodeSniffer/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.3.js
@@ -0,0 +1,2 @@
+
+alert('hi);
View
2 CodeSniffer/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.php
@@ -44,6 +44,8 @@ public function getErrorList($testFile='')
{
switch ($testFile) {
case 'EndFileNewlineUnitTest.3.inc':
+ case 'EndFileNewlineUnitTest.3.js':
+ case 'EndFileNewlineUnitTest.3.css':
return array(
2 => 1,
);
View
10 package.xml
@@ -34,7 +34,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Added PSR2 ControlStructureSpacingSniff to ensure there are no spaces before and after parenthesis in control structures
-- Fixes bug #19732 : PSR2: some control structures errors not reported
- Squiz commenting sniffs now support non-English characters when checking for capital letters
- -- Thanks to Roman Levishchenko for the contribution
+ -- Thanks to Roman Levishchenko for the patch
+ - Generic EndFileNewlineSniff now supports JS and CSS files
+ -- Thanks to Denis Ryabkov for the patch
- PSR1 SideEffectsSniff no longer reports constant declarations as side effects
- Notifysend report now supports notify-send versions before 0.7.3
-- Thanks to Ken Guest for the patch
@@ -516,8 +518,14 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP" name="ByteOrderMarkUnitTest.php" role="test">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
+ <file baseinstalldir="PHP" name="EndFileNewlineUnitTest.1.css" role="test" />
+ <file baseinstalldir="PHP" name="EndFileNewlineUnitTest.1.js" role="test" />
<file baseinstalldir="PHP" name="EndFileNewlineUnitTest.1.inc" role="test" />
+ <file baseinstalldir="PHP" name="EndFileNewlineUnitTest.2.css" role="test" />
+ <file baseinstalldir="PHP" name="EndFileNewlineUnitTest.2.js" role="test" />
<file baseinstalldir="PHP" name="EndFileNewlineUnitTest.2.inc" role="test" />
+ <file baseinstalldir="PHP" name="EndFileNewlineUnitTest.3.css" role="test" />
+ <file baseinstalldir="PHP" name="EndFileNewlineUnitTest.3.js" role="test" />
<file baseinstalldir="PHP" name="EndFileNewlineUnitTest.3.inc" role="test" />
<file baseinstalldir="PHP" name="EndFileNewlineUnitTest.php" role="test">
<tasks:replace from="@package_version@" to="version" type="package-info" />

0 comments on commit c7e4be4

Please sign in to comment.