The jslint Function


JSLint is delivered as a set of files:

browser.js Browser based UI.
function.html This page that you are looking at right now.
help.html Using jslint as a single page JSLint application.
index.html Single page JSLint application that uses the js files.
jslint.js The jslint function.
report.js The report object, containing report generator functions for HTML.

function jslint

The jslint function is written in ES6 JavaScript. It has no dependence on other files.

The jslint function has three arguments:

Parameter name Type VolitionDescription
sourcestring or arrayrequiredThis is the source of the program to be analyzed. It can be either a string containing \n, \r, or \r\n line breaks, or an array of strings, one element per line.
option_objectobject optionalThis object contains the chosen options for this analysis. The keys are the names of the options described on the help page. The values are either the boolean true or a small number.
global_arrayarrayoptional This is an array of strings. Each string names one global variable that may be used by the program. Listing names here will silence warnings about the names. It will not introduce the names into the runtime environment.

The jslint function will not modify any of its arguments.

The jslint function will return a result object contain the following properties:

Property name Type Content
directives array An array of comments containing directives.
editionstring The verison of jslint that produced the result.
exportsobject All of the exported names and values.
fromsarray All of the strings named in import statements.
functionsarray An array of function objects.
globalobject The global object, a body that contains the outermost statements and variables.
idstring "(JSLint)"
jsonboolean true if the source was a JSON text.
linesarray An array of strings, one for each line of text in the source.
moduleboolean true if the file contains an import or export.
okboolean true if no warnings were found.
optionobject The option object that was passed in, or an empty substitute.
propertyobject The names are the names of properties used in the source. The values are the number of times each name occurred.
stopboolean true if JSLint was not able to process the entire file.
tokensarray All of the token objects in source order.
treearray The token objects that represent the outermost statements. Those will be linked to other tokens, forming an abstract parse tree.
warningsarray The warning objects.


A source file is composed of tokens. Each identifier, each operator, each punctuator, each literal, and each comment is a token. The whitespace between tokens is not a token.

An object is made for each token. The properties in each token will vary according to the type of the token. More properties will be added to the tokens during the analysis to indicate the token's purpose or relationship with other tokens. The tokens will be woven together to form a tree.

Property name Type Description Where
arity string unary, binary, ternary, assignment, statement, variable, function, pre, post non-literals
block token or array of tokens This is the contents of a block or compound statement. Each token represents a statement. statement
body boolean true if the block is a function body. block
catch token The catch clause. try
closure boolean true if accessed by inner functions variable
complex boolean true if one or more parameters use new ES6 syntax function
constant boolean true if the thing is a compile-time constant token
context object The container of variables, parameters, labels, and exception variables declared in a function. function
directive boolean jslint, global, property comment
disrupt boolean true if a disruptive statement, or a block ending with a distruption. An if will disrupt if both of its branches disrupt. statement
dot boolean true if the previous token was a dot. identifier
ellipsis boolean true if the parameter or argument is preceded by the ellipsis. token
else array of tokens Alternate block in if (else), try (finally) statement
expression token or array of tokens One or more expressions. operator or statement
extra string get, set properties
flag object An object containing the properties g, i, m, u, or y. regexp
from number The starting position of the token within its line of source code. A token at the extreme left margin has a from of 0. token
parent token The function in which the variable was declared. variable
id string The id of the token. For most tokens, this is the token text itself.
For comments, id is "(comment)".
For number literals, id is "(number)".
For regular expression literals, id is "(regexp)".
For string literals, id is "(string)".
The end of the file has an id of "(end)".
The global object has an id of "(global)".
identifier boolean true if the token is an identifier. token
import string The import from string literal. import
label token The label of a statement, or the name of a property in an object literal. statement or object literal
level number The function nesting level. The global context is 0. The outermost functions are 1. Their inner functions are 2. function
line number The line number on which the token was found. A token on the first line will have a line of 0. If the token spans multiple lines (such as a long comment) line will be the number of the last line it occupied. token
name token or string The name of a function function
names token or array of tokens Parameters or variables on the left of =. = or (
nr number The token sequence number. token
parameters array of tokens The parameter list. function
parent token The function in which the variable was declared. variable
quote string The quote character. string literal
role string exception, function, label, parameter, variable identifier
shebang string The first line of text if it started with #! line
statement boolean true if the token is the first token of a statement. statement
strict token The "use strict" pragma. block
thru number The ending position of the token within its line of source code. It is usually from plus the length of the token. token
value string or array of strings The text of the token. For a long comment or megastring, this could be an array of strings. literals
variable token This links a variable to its definition. variable
warning object A warning object triggered by this token. token
wrapped boolean true if the expression was wrapped in parens. expression
writable boolean true if the variable may be assigned to. variable


The report object contains three functions that all take a result from the jslint function as input. report.js has no other dependence on other files.

Function name Description
error This function takes a result and returns an HTML text fragment from the warnings that are found.
function This function takes a result and returns an HTML text fragment detailing the declarations of every function.
property This function takes a result and returns a JSLint property directive. This directive could be pasted into a file.