Skip to content

JSLINT in a web page

Gabriel edited this page Aug 17, 2015 · 3 revisions

This shows how to use JSLint in a web page.

Call the JSLint function, passing in a source text (either a string or an array of strings), an optional options object, and an optional array of globals variables that the file is allowed readonly access.

jslint(source, options, globals);

jslint returns an object containing its results. The object contains a lot of valuable information. It can be used to generate reports. The object contains:

  • edition: the version of JSLint that did the analysis.
  • functions: an array of objects that represent all of the functions declared in the file.
  • global: an object representing the global object. Its .context property is an object containing a property for each global variable.
  • id: "(JSLint)"
  • imports: an array of strings representing each of the imports.
  • json: true if the file is a JSON text.
  • lines: an array of strings, the source.
  • module: true if an import or export statement was used.
  • ok: true if no warnings were generated. This is what you want.
  • option: the option argument.
  • property: a property object.
  • stop: true if JSLint was unable to finish. You don't want this.
  • tokens: an array of objects representing the tokens in the file.
  • tree: the token objects arranged in a tree.
  • warnings: an array of warning objects. A warning object can contain:
  • name: 'JSLintError'
  • column: A column number in the file.
  • line: A line number in the file.
  • code: A warning code string.
  • message: The warning message string.
  • a: Exhibit A.
  • b: Exhibit B.
  • c: Exhibit C.
  • d: Exhibit D.
Clone this wiki locally