Question

In a previous question Run JSLint on a .js file from debugging console in chrome or firefox I learned how to run JSLint from console or from node.

Is there a way to run JSLint (from the JavaScript code like in the answer given to the above mentioned question) but with custom options, for example for code that contains jQuery (JSLint validation for Javascript with JQuery) with the options Assume a browser and the option Predefined section with jQuery and $ as parameters?

Was it helpful?

Solution

Pass an object with the options as second parameter to JSLINT. Global variables can be defined as an array of strings and assigned to the predef property of said options object.

From the JSLint source code:

JSLINT is a global function. It takes two parameters.

var myResult = JSLINT(source, option);

The first parameter is either a string or an array of strings. If it is a string, it will be split on '\n' or '\r'. If it is an array of strings, it is assumed that each string represents one line. The source can be a JavaScript text, or HTML text, or a JSON text, or a CSS text.

The second parameter is an optional object of options that control the operation of JSLINT. Most of the options are booleans: They are all optional and have a default value of false. One of the options, predef, can be an array of names, which will be used to declare global variables, or an object whose keys are used as global names, with a boolean value that determines if they are assignable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top