At the weekend I released a new version of my JSLint for visual studio plugin. There have been some big changes made by Douglas Crockford in the last month, so given the lack of an official JSLint blog (most major updates are announced by Douglas Crockford on the mailing list) I will go over some of the recent changes.

Polarity

It has been somewhat confusing that JSLint options are sometimes written as "Tolerate xx" and sometimes as "Disallow xx". Douglas has changed all the options to now be in the tolerate form. Simply put, if all the options are false then JSLint is not tolerating anything and is being as strict as it can be.

In the VS extension these options are now settable separately between the different linters.

eqeq(eq) is back

After 5-6 months, Douglas has decided the option to tolerate == and != will now come back to JSLint as eqeq (previously it was eqeqeq and had a reversed meaning). I felt strongly it should come back so that linting pre-existing code did not require the difficult work of converting == and !=, so I am glad it is back, but I also strongly urge people not to turn it on if they are writing new files. I suspect Douglas has allowed it because of the new confusion option...

Confusion

JSLint now attempts to type local variables and warn when they are used inconsistently. For example...

var a = function() {
  var b = 0;
  b = "string"; // error - number confused with string
  if (b) {
    return 1;
  } else {
    return "string"; // error - number confused with string (returning different types)
  }
};

The support doesn't seem fully worked out yet (people are still raising some bugs), but it looks to be a great addition to JSLint.

Other changes...

In the "Dangling _" option, this previously just warned about fields ending in "_", but now it also warns for fields beginning with "_".

In the code "a ? a : b" we now get a suggestion that this be re-written as "a || b". This is in my opinion a great change that spreads the use of the || operator, teaching people that it just returns the first truthy option.

JSHint

I've previously mentioned that I wish JSHint were forked and kept merged with JSLint so we could get the benefits of more control over warnings but keep new features. However it is not and consequently the changes in JSHint are less extensive..

  • support for dojo global defines
  • a new option for whether unescaped dash's should be allowed in regex's
  • a new option for allowing href = "javascript:..." assignments