svn: /pear/packages/PHP_CodeSniffer/trunk/ CodeSniffer/Tokenizers/JS.php CodeSniffer/Tokens.php package.xml

From: Date: Mon, 06 Sep 2010 06:44:28 +0000
Subject: svn: /pear/packages/PHP_CodeSniffer/trunk/ CodeSniffer/Tokenizers/JS.php CodeSniffer/Tokens.php package.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-60259@lists.php.net to get a copy of this message
squiz Mon, 06 Sep 2010 06:44:28 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=303066 Log: Improved regular expression detection in JavaScript files. Fixes bug #17611 : Regular expression tokens not recognised. Bug: http://pear.php.net/bugs/17611 (unknown) Changed paths: U pear/packages/PHP_CodeSniffer/trunk/CodeSniffer/Tokenizers/JS.php U pear/packages/PHP_CodeSniffer/trunk/CodeSniffer/Tokens.php U pear/packages/PHP_CodeSniffer/trunk/package.xml Modified: pear/packages/PHP_CodeSniffer/trunk/CodeSniffer/Tokenizers/JS.php =================================================================== --- pear/packages/PHP_CodeSniffer/trunk/CodeSniffer/Tokenizers/JS.php 2010-09-06 04:44:15 UTC (rev 303065) +++ pear/packages/PHP_CodeSniffer/trunk/CodeSniffer/Tokenizers/JS.php 2010-09-06 06:44:28 UTC (rev 303066) @@ -165,6 +165,7 @@ 'false' => 'T_FALSE', 'null' => 'T_NULL', 'this' => 'T_THIS', + 'typeof' => 'T_TYPEOF', '(' => 'T_OPEN_PARENTHESIS', ')' => 'T_CLOSE_PARENTHESIS', '{' => 'T_OPEN_CURLY_BRACKET', @@ -832,6 +833,8 @@ T_BITWISE_OR, T_BITWISE_AND, T_COMMA, + T_COLON, + T_TYPEOF, ); $afterTokens = array( @@ -840,6 +843,7 @@ ';', ' ', '.', + $eolChar, ); // Find the last non-whitespace token that was added @@ -873,8 +877,8 @@ break; } } else { - $possiblEolChar = substr($string, $next, strlen($eolChar)); - if ($possiblEolChar === $eolChar) { + $possibleEolChar = substr($string, $next, strlen($eolChar)); + if ($possibleEolChar === $eolChar) { // This is the last token on the line and regular // expressions need to be defined on a single line, // so this is not a regular expression. @@ -884,6 +888,10 @@ } if ($chars[$next] !== '/') { + if (PHP_CODESNIFFER_VERBOSITY > 1) { + echo "\t* could not find end of regular expression *".PHP_EOL; + } + return null; } @@ -895,13 +903,16 @@ } $regexEnd = $next; + if (PHP_CODESNIFFER_VERBOSITY > 1) { + echo "\t* found end of regular expression at token $regexEnd *".PHP_EOL; + } for ($next = ($next + 1); $next < $numChars; $next++) { if ($chars[$next] !== ' ') { break; } else { - $possiblEolChar = substr($string, $next, strlen($eolChar)); - if ($possiblEolChar === $eolChar) { + $possibleEolChar = substr($string, $next, strlen($eolChar)); + if ($possibleEolChar === $eolChar) { // This is the last token on the line. break; } @@ -909,6 +920,10 @@ } if (in_array($chars[$next], $afterTokens) === false) { + if (PHP_CODESNIFFER_VERBOSITY > 1) { + echo "\t* tokens after regular expression do not look correct *".PHP_EOL; + } + return null; } Modified: pear/packages/PHP_CodeSniffer/trunk/CodeSniffer/Tokens.php =================================================================== --- pear/packages/PHP_CodeSniffer/trunk/CodeSniffer/Tokens.php 2010-09-06 04:44:15 UTC (rev 303065) +++ pear/packages/PHP_CodeSniffer/trunk/CodeSniffer/Tokens.php 2010-09-06 06:44:28 UTC (rev 303066) @@ -59,14 +59,15 @@ define('T_STYLE', 1041); define('T_ASPERAND', 1042); define('T_DOLLAR', 1043); +define('T_TYPEOF', 1044); // Some PHP 5.3 tokens. if (defined('T_NAMESPACE') === false) { - define('T_NAMESPACE', 1044); + define('T_NAMESPACE', 1045); } if (defined('T_NS_SEPARATOR') === false) { - define('T_NS_SEPARATOR', 1045); + define('T_NS_SEPARATOR', 1046); } /** Modified: pear/packages/PHP_CodeSniffer/trunk/package.xml =================================================================== --- pear/packages/PHP_CodeSniffer/trunk/package.xml 2010-09-06 04:44:15 UTC (rev 303065) +++ pear/packages/PHP_CodeSniffer/trunk/package.xml 2010-09-06 06:44:28 UTC (rev 303066) @@ -29,6 +29,9 @@ - Added Generic ClosureLinterSniff to run Google's gjslint over your JS files - Fixed issue with Squiz FunctionCommentSniff reporting incorrect type hint when default value uses namespace -- Thanks to Anti Veeranna for the patch + - Improved regular expression detection in JavaScript files + -- Added new T_TYPEOF token that can be used to target the typeof JS operator + -- Fixes bug #17611 : Regular expression tokens not recognised </notes> <contents> <dir name="/">

« previous php.pear.cvs (#60259) next »