Reputation: 930
I am trying to build a simple JavaScript validator, something like JSHint. I want to write a JavaScript code and click a "Validate" button, and the errors should show up.
Passing the JavaScript source like this JSHINT(js-source) just gives you "true" or "false" depending on whether the code is valid or not. I would like to get the details (e.g. line number where the error ocurred, error type etc.) of each error.
Here's what I already have.
http://jsbin.com/AZEpOHi/1/edit
Upvotes: 4
Views: 1307
Reputation: 1899
From the docs:
If your input passes JSHint tests, the function will return true. Otherwise, it will return false. In that case, you can use JSHINT.errors to retrieve the errors or request a complete report by calling the JSHINT.data() method.
The errors are in the JSHINT.errors
array, and those objects include line numbers and error reasons.
Here's a jsfiddle that demonstrates a simple use of JSHINT.errors.
Upvotes: 3