简体   繁体   中英

How to show JavaScript errors using JSHint?

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 (eg line number where the error ocurred, error type etc.) of each error.

Here's what I already have.

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM