JSHint exposes a JavaScript API for programmatic access in environments like web browsers and Node.js.
JSHINT( source, options, predef )Analyze source code for errors and potential problems.
Parameters:
sourceJSHINT(["'use strict';", "console.log('hello, world!');"]);optionsJSHINT(mySource, { undef: true });predefglobals linting
optionJSHINT(mySource, myOptions, { jQuery: false });JSHINT.errorsAn array of warnings and errors generated by the most recent invocation of
JSHINT.
JSHINT.data()Generate a report containing details about the most recent invocation of
JSHINT.
For example, the following code:
var source = [
'function goo() {}',
'foo = 3;'
];
var options = {
undef: true
};
var predef = {
foo: false
};
JSHINT(source, options, predef);
console.log(JSHINT.data());
...will produce the following output:
{
functions: [
{
name: 'goo',
param: undefined,
line: 1,
character: 14,
last: 1,
lastcharacter: 18,
metrics: {
complexity: 1,
parameters: 0,
statements: 0
}
}
],
options: {
undef: true,
indent: 4,
maxerr: 50
},
errors: [
{
id: '(error)',
raw: 'Read only.',
code: 'W020',
evidence: 'foo = 3;',
line: 2,
character: 1,
scope: '(main)',
a: undefined,
b: undefined,
c: undefined,
d: undefined,
reason: 'Read only.'
}
],
globals: [
'goo',
'foo'
],
unused: [
{
name: 'goo',
line: 1, character: 10
}
]
}