Most Powerful Open Source ERP

Guideline Code Must Be Validated With JsLint

To ensure consistent syntax and quality.
  • Last Update:2017-04-13
  • Version:001
  • Language:en

Code Must Be Validated With JsLint

JSLint (http://jslint.com/) is a quality tools that inspects code and warns about potential problems. It is available online and can also be integrated into several development environments, so errors will be highlighted when writing code.

Before validating your code in JSLint, you should use a code beautifier to fix basic syntax errors (like indentation) automatically. There are a number of beautifiers available online. The following seem to be the best working:

Here, javascript sources have to begin with this header: /*jslint indent: 2, maxlen: 80, nomen: true */, which means it uses two spaces indentation, 80 maximum characters by line and allow the use of '_' as first variable name character. Other JSLint options can be added in sub functions if necessary; Allowed options are:

  • ass: true if assignment should be allowed outside of statement position.
  • bitwise: true if bitwise operators should be allowed.
  • continue: true if the continue statement should be allowed.
  • newcap: true if Initial Caps with constructor function is optional.
  • regexp: true if . and [^...] should be allowed in RegExp literals. They match more material than might be expected, allowing attackers to confuse applications. These forms should not be used when validating in secure applications.
  • unparam: true if warnings should not be given for unused parameters.

Good Example:

/*jslint indent: 2, maxlen: 80, nomen: true */
/*global jIO */
(function (jIO) {
  "use strict";
  var my_code = "is",
      perfect = "isn't it?";

  function doSomething(parameter_one) {
    return jIO.util.ajax({url: parameter_one});
  }

  // camel case tolerated for libraries
  window.myLib = {
    other_entries: "text",
    doSomething: doSomething
  };
}(jIO));

Bad Example:

var myCode = "is", perfect = "isn't it?";

var myLib = {
  otherEntries: "text",
  doSomething: function doSomething(parameterOne) {
    return jIO.util.ajax({url: parameterOne});
  }
};