cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Debug JavaScriptLintSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug JavaScriptLintUnitTest.js JavaScriptLintUnitTest.php
| From: | Greg Sherwood | Date: | Mon, 31 Mar 2008 00:52:00 +0000 |
| Subject: | cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Debug JavaScriptLintSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug JavaScriptLintUnitTest.js JavaScriptLintUnitTest.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-51755@lists.php.net to get a copy of this message | ||
squiz Mon Mar 31 00:52:00 2008 UTC
Added files:
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Debug
JavaScriptLintSniff.php
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug
JavaScriptLintUnitTest.js
JavaScriptLintUnitTest.php
Modified files:
/pear/PHP_CodeSniffer package.xml
Log:
Added Squiz JavaScriptLintSniff to check JS files with JSL
http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/package.xml?r1=1.258&r2=1.259&diff_format=u Index: pear/PHP_CodeSniffer/package.xml diff -u pear/PHP_CodeSniffer/package.xml:1.258 pear/PHP_CodeSniffer/package.xml:1.259 --- pear/PHP_CodeSniffer/package.xml:1.258 Wed Mar 26 00:14:43 2008 +++ pear/PHP_CodeSniffer/package.xml Mon Mar 31 00:52:00 2008 @@ -66,6 +66,8 @@ - Generic MultipleStatementAlignmentSniff now supports JS files - Added Squiz ObjectMemberCommaSniff to ensure the last member of a JS object is not followed by a comma - Added Squiz ConstantCaseSniff to ensure the PHP constants are uppercase and JS lowercase + - Added Squiz JavaScriptLintSniff to check JS files with JSL + -- Set path using phpcs --config-set jsl_path /path/to/jsl - Added MySource FirebugConsoleSniff to ban the use of "console" for JS variable and function names - Added MySource JoinStringsSniff to enforce the use of join() to concatenate JS strings - Added MySource AssignThisSniff to ensure this is only assigned to a var called self @@ -764,6 +766,11 @@ <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> + <dir name="Debug"> + <file baseinstalldir="PHP" name="JavaScriptLintSniff.php" role="php"> + <tasks:replace from="@package_version@" to="version" type="package-info" /> + </file> + </dir> <dir name="Files"> <file baseinstalldir="PHP" name="LineEndingsSniff.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> @@ -1061,6 +1068,12 @@ <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> + <dir name="Debug"> + <file baseinstalldir="PHP" name="JavaScriptLintUnitTest.js" role="test" /> + <file baseinstalldir="PHP" name="JavaScriptLintUnitTest.php" role="test"> + <tasks:replace from="@package_version@" to="version" type="package-info" /> + </file> + </dir> <dir name="Files"> <file baseinstalldir="PHP" name="FileExtensionUnitTest.inc" role="test" /> <file baseinstalldir="PHP" name="FileExtensionUnitTest.php" role="test"> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php <?php /** * Squiz_Sniffs_Debug_JavaScriptLintSniff. * * PHP version 5 * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence * @version CVS: $Id: JavaScriptLintSniff.php,v 1.1 2008/03/31 00:52:00 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Squiz_Sniffs_Debug_JavaScriptLintSniff. * * Runs JavaScipt Lint on the file. * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence * @version Release: @package_version@ * @link http://pear.php.net/package/PHP_CodeSniffer */ class Squiz_Sniffs_Debug_JavaScriptLintSniff implements PHP_CodeSniffer_Sniff { /** * A list of tokenizers this sniff supports. * * @var array */ public $supportedTokenizers = array('JS'); /** * Returns the token types that this sniff is interested in. * * @return array(int) */ public function register() { return array(T_OPEN_TAG); }//end register() /** * Processes the tokens that this sniff is interested in. * * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. * @param int $stackPtr The position in the stack where * the token was found. * * @return void */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $fileName = $phpcsFile->getFilename(); $jslPath = PHP_CodeSniffer::getConfigData('jsl_path'); if (is_null($jslPath) === true) { return; } $cmd = $jslPath.' -nologo -nofilelisting -nocontext -nosummary -output-format __LINE__:__ERROR__ -process '.$fileName; $msg = exec($cmd, $output, $retval); // $exitCode is the last line of $output if no error occures, on error it // is numeric. Try to handle various error conditions and provide useful // error reporting. if ($retval === 2 || $retval === 4) { if (is_array($output) === true) { $msg = join('\n', $output); } throw new PHP_CodeSniffer_Exception("Failed invoking JavaScript Lint, retval was [$retval], output was [$msg]"); } if (is_array($output) === true) { $tokens = $phpcsFile->getTokens(); foreach ($output as $finding) { $split = strpos($finding, ':'); $line = substr($finding, 0, $split); $message = substr($finding, ($split + 1)); // Find the token at the start of the line. $lineToken = null; foreach ($tokens as $ptr => $info) { if ($info['line'] == $line) { $lineToken = $ptr; break; } } if ($lineToken !== null) { $phpcsFile->addWarning(trim($message), $ptr); } }//end foreach }//end if }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.js?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.js +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.js alert('hi') alert('hi'); http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.php <?php /** * Unit test class for the JavaScriptLint sniff. * * PHP version 5 * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence * @version CVS: $Id: JavaScriptLintUnitTest.php,v 1.1 2008/03/31 00:52:00 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the JavaScriptLint sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence * @version Release: @package_version@ * @link http://pear.php.net/package/PHP_CodeSniffer */ class Squiz_Tests_Debug_JavaScriptLintUnitTest extends AbstractSniffUnitTest { /** * Should this test be skipped for some reason. * * @return void */ protected function shouldSkipTest() { $jslPath = PHP_CodeSniffer::getConfigData('jsl_path'); return (is_null($jslPath)); }//end shouldSkipTest() /** * Returns the lines where errors should occur. * * The key of the array should represent the line number and the value * should represent the number of errors that should occur on that line. * * @return array(int => int) */ public function getErrorList() { return array(); }//end getErrorList() /** * Returns the lines where warnings should occur. * * The key of the array should represent the line number and the value * should represent the number of warnings that should occur on that line. * * @return array(int => int) */ public function getWarningList() { return array( 2 => 1, ); }//end getWarningList() }//end class ?>
http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/package.xml?r1=1.258&r2=1.259&diff_format=u Index: pear/PHP_CodeSniffer/package.xml diff -u pear/PHP_CodeSniffer/package.xml:1.258 pear/PHP_CodeSniffer/package.xml:1.259 --- pear/PHP_CodeSniffer/package.xml:1.258 Wed Mar 26 00:14:43 2008 +++ pear/PHP_CodeSniffer/package.xml Mon Mar 31 00:52:00 2008 @@ -66,6 +66,8 @@ - Generic MultipleStatementAlignmentSniff now supports JS files - Added Squiz ObjectMemberCommaSniff to ensure the last member of a JS object is not followed by a comma - Added Squiz ConstantCaseSniff to ensure the PHP constants are uppercase and JS lowercase + - Added Squiz JavaScriptLintSniff to check JS files with JSL + -- Set path using phpcs --config-set jsl_path /path/to/jsl - Added MySource FirebugConsoleSniff to ban the use of "console" for JS variable and function names - Added MySource JoinStringsSniff to enforce the use of join() to concatenate JS strings - Added MySource AssignThisSniff to ensure this is only assigned to a var called self @@ -764,6 +766,11 @@ <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> + <dir name="Debug"> + <file baseinstalldir="PHP" name="JavaScriptLintSniff.php" role="php"> + <tasks:replace from="@package_version@" to="version" type="package-info" /> + </file> + </dir> <dir name="Files"> <file baseinstalldir="PHP" name="LineEndingsSniff.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> @@ -1061,6 +1068,12 @@ <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> + <dir name="Debug"> + <file baseinstalldir="PHP" name="JavaScriptLintUnitTest.js" role="test" /> + <file baseinstalldir="PHP" name="JavaScriptLintUnitTest.php" role="test"> + <tasks:replace from="@package_version@" to="version" type="package-info" /> + </file> + </dir> <dir name="Files"> <file baseinstalldir="PHP" name="FileExtensionUnitTest.inc" role="test" /> <file baseinstalldir="PHP" name="FileExtensionUnitTest.php" role="test"> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php <?php /** * Squiz_Sniffs_Debug_JavaScriptLintSniff. * * PHP version 5 * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence * @version CVS: $Id: JavaScriptLintSniff.php,v 1.1 2008/03/31 00:52:00 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Squiz_Sniffs_Debug_JavaScriptLintSniff. * * Runs JavaScipt Lint on the file. * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence * @version Release: @package_version@ * @link http://pear.php.net/package/PHP_CodeSniffer */ class Squiz_Sniffs_Debug_JavaScriptLintSniff implements PHP_CodeSniffer_Sniff { /** * A list of tokenizers this sniff supports. * * @var array */ public $supportedTokenizers = array('JS'); /** * Returns the token types that this sniff is interested in. * * @return array(int) */ public function register() { return array(T_OPEN_TAG); }//end register() /** * Processes the tokens that this sniff is interested in. * * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. * @param int $stackPtr The position in the stack where * the token was found. * * @return void */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $fileName = $phpcsFile->getFilename(); $jslPath = PHP_CodeSniffer::getConfigData('jsl_path'); if (is_null($jslPath) === true) { return; } $cmd = $jslPath.' -nologo -nofilelisting -nocontext -nosummary -output-format __LINE__:__ERROR__ -process '.$fileName; $msg = exec($cmd, $output, $retval); // $exitCode is the last line of $output if no error occures, on error it // is numeric. Try to handle various error conditions and provide useful // error reporting. if ($retval === 2 || $retval === 4) { if (is_array($output) === true) { $msg = join('\n', $output); } throw new PHP_CodeSniffer_Exception("Failed invoking JavaScript Lint, retval was [$retval], output was [$msg]"); } if (is_array($output) === true) { $tokens = $phpcsFile->getTokens(); foreach ($output as $finding) { $split = strpos($finding, ':'); $line = substr($finding, 0, $split); $message = substr($finding, ($split + 1)); // Find the token at the start of the line. $lineToken = null; foreach ($tokens as $ptr => $info) { if ($info['line'] == $line) { $lineToken = $ptr; break; } } if ($lineToken !== null) { $phpcsFile->addWarning(trim($message), $ptr); } }//end foreach }//end if }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.js?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.js +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.js alert('hi') alert('hi'); http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Debug/JavaScriptLintUnitTest.php <?php /** * Unit test class for the JavaScriptLint sniff. * * PHP version 5 * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence * @version CVS: $Id: JavaScriptLintUnitTest.php,v 1.1 2008/03/31 00:52:00 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the JavaScriptLint sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence * @version Release: @package_version@ * @link http://pear.php.net/package/PHP_CodeSniffer */ class Squiz_Tests_Debug_JavaScriptLintUnitTest extends AbstractSniffUnitTest { /** * Should this test be skipped for some reason. * * @return void */ protected function shouldSkipTest() { $jslPath = PHP_CodeSniffer::getConfigData('jsl_path'); return (is_null($jslPath)); }//end shouldSkipTest() /** * Returns the lines where errors should occur. * * The key of the array should represent the line number and the value * should represent the number of errors that should occur on that line. * * @return array(int => int) */ public function getErrorList() { return array(); }//end getErrorList() /** * Returns the lines where warnings should occur. * * The key of the array should represent the line number and the value * should represent the number of warnings that should occur on that line. * * @return array(int => int) */ public function getWarningList() { return array( 2 => 1, ); }//end getWarningList() }//end class ?>