Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Request #18498 Update the rhino / jslint
Submitted: 2011-05-02 17:23 UTC
From: kingsquare Assigned:
Status: Open Package: PHP_CodeSniffer (version 1.3.0)
PHP Version: Irrelevant OS: Ubuntu
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 25 - 8 = ?

 
 [2011-05-02 17:23 UTC] kingsquare (Kingsquare Information Services)
Description: ------------ Since a while now Douglas Crockford hasnt supported Rhino in his JSLint project. Now including support is fairly straightforward: add this piece of javascript to the end of jslint.js (@see http://thecodetrain.co.uk/2011/04/making-php-codesniffer- use-jslint-via-rhino/) : (function (a) { var e, i, input; if (!a[0]) { print("Usage: jslint.js file.js"); quit(1); } input = readFile(a[0]); if (!input) { print("jslint: Couldn't open file '" + a[0] + "'."); quit(1); } if (!JSLINT(input, {bitwise: true, eqeqeq: true, immed: true, newcap: true, nomen: true, onevar: true, plusplus: true, regexp: true, rhino: true, undef: true, white: true})) { for (i = 0; i < JSLINT.errors.length; i += 1) { e = JSLINT.errors[i]; if (e) { print('Lint at line ' + e.line + ' character ' + e.character + ': ' + e.reason); print((e.evidence || ''). replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1")); print(''); } } quit(2); } else { print("jslint: No problems found in " + a[0]); quit(); } }(arguments)); and thats it. But this also includes the various options to be set on the JSLint itself. I've modified this into allowing of sending the actuel JSLint configuration object: // rhino.js // 2009-09-11 /* Copyright (c) 2002 Douglas Crockford (www.JSLint.com) Rhino Edition */ // This is the Rhino companion to fulljslint.js. /*global JSLINT */ /*jslint rhino: true, strict: false */ (function (a) { var e, i, input, options = {bitwise: true, eqeqeq: true, immed: true, newcap: true, nomen: true, onevar: true, plusplus: true, regexp: true, rhino: true, undef: true, white: true}; if (!a[0]) { print("Usage: jslint.js file.js"); quit(1); } input = readFile(a[0]); if (!input) { print("jslint: Couldn't open file '" + a[0] + "'."); quit(1); } if (!JSLINT(input, ((!a[1])?options:a[1]))) { for (i = 0; i < JSLINT.errors.length; i += 1) { e = JSLINT.errors[i]; if (e) { print('Lint at line ' + e.line + ' character ' + e.character + ': ' + e.reason); print((e.evidence || ''). replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1")); print(''); } } quit(2); } else { print("jslint: No problems found in " + a[0]); quit(); } }(arguments)); This would allow the codesniffer rule to send along its configuration: class Squiz_Sniffs_Debug_JSLintSniff: public $jsLintConfig = '{bitwise: true, eqeqeq: true, immed: true, newcap: true, nomen: true, onevar: true, plusplus: true, regexp: true, rhino: true, undef: true, white: true}'; /* .. line 72 ..*/ $cmd = "$rhinoPath \"$jslintPath\" \"$fileName\" \"$this- >jsLintConfig\""; This would allow easier reuse of the sniff via a rule: <rule ref="Squiz.Debug.JSLing"> <properties> <property name="jsLintConfig" value="{plusplus: true, regexp: true, rhino: true, undef: true, white: true}"/> </properties> </rule> instead of having to copy/paste the entire sniff just to allow the setting of custom configuration.. I know the public variable for jsLintConfig is pretty ugly, but this way it works and allows for easier reconfiguration

Comments

 [2011-05-02 18:40 UTC] kingsquare (Kingsquare Information Services)
Hmmm... seems i was too lazy :D The passing of arguments in rhino.js: /* ... */ if (typeof a[1] !== 'undefined') { eval('options = ' + a[1]); } if (!JSLINT(input, options)) { Furthermore i changed the $cmd construction to: $cmd = $rhinoPath.' ' .escapeshellarg($jslintPath).' ' .escapeshellarg($fileName).' ' .escapeshellarg(preg_replace("!\s!", "", $this->config)); And the preg_match to: $numMatches = preg_match('/^Lint at line ([0-9]+)[^:]*:(.*)$/', $finding, $matches);