zsd
zsd

Reputation: 439

jslint4java external jslint options are ignored

I'm using phing-drupal-template and have problem with jslinting. When using an external jslint with the --jslint option neither --browser option nor inline options are recognized like

/*jslint browser: true */

Any help would be much appreciated. thx.

java -jar tools/jslint4java/jslint4java-2.0.5/jslint4java-2.0.5.jar
     --browser 
     --predef "jQuery,$,Modernizr" 
     ../sites/all/modules/custom/zendigital/js/frontpage.js



java -jar tools/jslint4java/jslint4java-2.0.5/jslint4java-2.0.5.jar 
     --jslint tools/jslint/fulljslint.js
     --browser
     --predef "jQuery,$,Modernizr"
     ../sites/all/modules/custom/zendigital/js/frontpage.js 


jslint:...frontpage.js:59:40:'window' is not defined.
jslint:...frontpage.js:84:23:'window' is not defined.
jslint:...frontpage.js:104:36:'window' is not defined.
jslint:...frontpage.js:105:23:'window' is not defined.
jslint:...frontpage.js:180:25:'Modernizr' is not defined.
jslint:...frontpage.js:250:65:'window' is not defined.
jslint:...frontpage.js:250:86:'window' is not defined.
jslint:...frontpage.js:278:4:'jQuery' is not defined.

Upvotes: 0

Views: 109

Answers (1)

ruffin
ruffin

Reputation: 17473

Does the behavior exist if you use the canonical jslint file? The one you linked branched over four years ago, hasn't been updated, and doesn't seem to respect window.

Compare this section in the canonical, current JSLint file, which does contain window:
https://github.com/douglascrockford/JSLint/blob/master/jslint.js#L343

// browser contains a set of global names that are commonly provided by a
// web browser environment.

    browser = array_to_object([
        'clearInterval', 'clearTimeout', 'document', 'event', 'FormData',
        'frames', 'history', 'Image', 'localStorage', 'location', 'name',
        'navigator', 'Option', 'parent', 'screen', 'sessionStorage',
        'setInterval', 'setTimeout', 'Storage', 'window', 'XMLHttpRequest'
    ], false),

... with this from your version without any updates since Nov 2010, which doesn't contain window.
https://github.com/mikewest/JSLint/blob/master/fulljslint.js#L340

// browser contains a set of global names which are commonly provided by a
// web browser environment.

browser = {
    addEventListener: false,
    blur : false,
    clearInterval : false,
    clearTimeout : false,
    close : false,
    closed : false,
    defaultStatus : false,
    document : false,
    event : false,
    focus : false,
    frames : false,
    getComputedStyle: false,
    history : false,
    Image : false,
    length : false,
    location : false,
    moveBy : false,
    moveTo : false,
    name : false,
    navigator : false,
    onbeforeunload : true,
    onblur : true,
    onerror : true,
    onfocus : true,
    onload : true,
    onresize : true,
    onunload : true,
    open : false,
    opener : false,
    Option : false,
    parent : false,
    print : false,
    removeEventListener: false,
    resizeBy : false,
    resizeTo : false,
    screen : false,
    scroll : false,
    scrollBy : false,
    scrollTo : false,
    setInterval : false,
    setTimeout : false,
    status : false,
    top : false,
    XMLHttpRequest : false
},

I haven't looked into --predef "jQuery,$,Modernizr" at all.

I wouldn't suggest using a relatively anonymously branched JSLint file in general, much less one that's been sitting for four years. Which of its changes are you utilizing? It might be easier to add that to a more current JSLint version that respects window -- or use JSHint to get the same changes, if they're useful and there. (Or, as I'll usually argue, you can always just take JSLint's advice. ;^D)

Good luck. Let us know if the canonical version works.


EDIT: You might try the widget setting for your out-of-date version. That appears to have window in it:

// widget contains the global names which are provided to a Yahoo //
(fna Konfabulator) widget.

widget = {
    alert : true,
    animator : true,
    appleScript : true,
    beep : true,
    //...
    Window : true,
    XMLDOM : true,
    XMLHttpRequest : true,
    yahooCheckLogin : true,
    yahooLogin : true,
    yahooLogout : true
},

That said, you're so non-standard at this point (widget is not a current JSLint directive and contains a lot of Konfabulator-related cruft), you really should ditch this fork and update to the current, canonical version. This is more a "for fun experiment" than a recommended fix.

You might also be able to just insert window: true, into the browser array, but, again, you're better off making the edits you need from that branch in a current version of JSLint, using JSHint if it has them, or simply following the current version of JSLint's advice.

That said, I can't replicate the issue you're seeing with a minimal JSLint wrapper with the old, branched version; it's letting tons of stuff through. Sorry, wish I could be more helpful.

Upvotes: 0

Related Questions