[dokuwiki] Using JSLint

I've been working for some time on a plugin for DokuWiki which uses some Javascript. Of course, I want as much as possible to satisfy the rules for plugins and use of various features such as javascript. On the info page for use of javascript (http://wiki.splitbrain.org/wiki:devel:javascript), it is recommended that we pass out scripts through JSLint, because if the scripts don't conform to JSLint, errors will creep in when DokuWiki compresses the Javascript But it's hard to know how far to take the warnings emitted by JSLint, which at least to me seem a bit quirky.

For instance, it doesn't like you to create an array using the class constructor:
      Problem at line 29 character 34: Use the array literal notation [].
   var selected_files = new Array();

It also prefers the "dot notations" over array notation for accessing properties: Problem at line 59 character 23: ['abs_path'] is better written in dot notation.
    var index = f['abs_path'].selectedIndex;

Then it doesn't like you to declare variables inside a block.  For instance:
   for(var i=0; i<a.length;i++) {
      var b=get_b();
      var c=get_c();
    /*  do something */
 }

It would prefer that you declare a and b in advance.

  var b;
  var c;
   for(var i=0; i<a.length;i++) {
       b=get_b();
       c=get_c();
    /*  do something */
 }

It even objects to:

if(x == y) {
  var q = x;
}

But in fact Javascript doesn't recognize block scope: "Javacript does not have block-level scope. All variables declared in a function, no matter where they are declared, are defined throughout the function" (Flanagan, Definitive Guide). I'm not interested in splitting hairs or arguing with JSLint. Basically, I simply would like to know how far we have to carry our conformity to JSLint without causing ourselves problems.

Thanks.

--

_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: