[英]How to show all the errors and get a JSHint report in JavaScript?
I have the following code that validates JavaScript code: 我有以下代码可验证JavaScript代码:
var jsCode = "....."; // JavaScript code here
var success = JSHint(jsCode); //
alert(success); // Shows whether 'true' or 'false'
How can I show the list of all errors in the code instead of just 'true' or 'false'? 如何显示代码中所有错误的列表,而不仅仅是“ true”或“ false”? In the documentation, it says, " In that case, you can use JSHINT.errors to retrieve the errors or request a complete report by calling the JSHINT.data() method. "
在文档中说:“ 在这种情况下,您可以使用JSHINT.errors来检索错误或通过调用JSHINT.data()方法来请求完整的报告。 ”
Try this: 尝试这个:
var jsCode = "....."; // JavaScript code here
var success = JSHint(jsCode); //
var data = JSHINT.data();
//Print out list of object props:
for(var i=0; i<data.functions.length; i++){
for(var j in data.functions[i]){
document.write(j + ': '+ data.functions[i][j] +'<br>');
}
}
Validate Javascript code is a task that need to be automate. 验证Javascript代码是一项需要自动化的任务。 To automate task you need to use Grunt .
要自动化任务,您需要使用Grunt 。
Grunt is an automate task for javascript based projects, then you achieve dependency management, js validate, reports.... etc. Grunt是针对基于javascript的项目的自动化任务,然后实现依赖项管理,js验证,报告等。
The grunt-contrib-jshint plugin could help you. grunt-contrib-jshint插件可以为您提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.