How to show JavaScript errors using JSHint?

I am trying to create a simple JavaScript validator, something like JSHint . I want to write JavaScript code and click the "Check" button and errors will appear.

Passing a 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 information (for example, the line number where the error occurred, the type of error, etc.) of each error.

Here is what I already have.

http://jsbin.com/AZEpOHi/1/edit

+4
source share
1 answer

From the docs :

If your input passes JSHint tests, the function will return true. Otherwise, it will return false. In this case, you can use JSHINT.errors to get errors or request a full report by calling the JSHINT.data () method.

Errors are in the JSHINT.errors array, and these objects include line numbers and causes of the error.

Here's a jsfiddle that demonstrates a simple use of JSHINT.errors .

+3
source

All Articles