在 chrome 或 Firefox 中的调试控制台对.js文件运行 JSLint
Run JSLint on a .js file from debugging console in chrome or firefox
是否可以通过在Chrome或Firefox中的调试/开发人员控制台的标头中加载JSLint来在一个或多个.js文件上运行JSLint
?
我想这样做的原因是我想在JSON
中打印console.log()
JSLint
的解析,它在文档中说:
// You can obtain the parse tree that JSLint constructed while parsing. The
// latest tree is kept in JSLINT.tree. A nice stringication can be produced
// with
// JSON.stringify(JSLINT.tree, [
// 'string', 'arity', 'name', 'first',
// 'second', 'third', 'block', 'else'
// ], 4));
您可以使用
以下语法在 JavaScript 代码上运行 JSLint:
var code = "var a = 1 + 2;";
JSLINT(code);
您可以打印语法树,如问题中所述。
现在在你的例子中,你需要从JavaScript文件中读取JavaScript源代码。您可以进行 AJAX 调用以将 JavaScript 文件的源代码读入变量。然后像上面一样调用 JSLINT 传递该变量。使用 jQuery 的示例如下所示。
$(function() {
// Include jslint.js
$('<script src="http://localhost/yourapp/jslint.js">').appendTo("head");
// Read JavaScript file contents into 'code'
$.get('http://localhost/yourapp/somescript.js', function(code) {
// Run JSLINT over code
JSLINT(code);
// Print the parse tree
console.log(JSON.stringify(JSLINT.tree, [
'string', 'arity', 'name', 'first',
'second', 'third', 'block', 'else'
], 4));
});
});
根据您要实现的目标,一个独立的JavaScript控制台(例如。NodeJS)将是比浏览器控制台更好的选择。我想JSLint存在Node包。但是,如果您想手动包含它,您可以简单地执行以下操作。
首先在 jslint 末尾添加以下行.js
exports.JSLINT = JSLINT;
然后用mycode.js编写你的代码。
var fs = require("fs");
var jslint = require("./jslint.js");
fs.readFile("./test.js", function(err, code) {
var source = code.toString('ascii');
jslint.JSLINT(source);
console.log(JSON.stringify(jslint.JSLINT.tree, [
'string', 'arity', 'name', 'first',
'second', 'third', 'block', 'else'
], 4));
},"text");
然后按以下方式从控制台运行代码:
node mycode.js
相关文章:
- JS文件的路径正在消失
- 我的外部js文件无法加载
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件
- 动态加载和卸载js文件
- 如何将变量传递到另一个js文件
- 如何将所有JS文件连接到一个文件夹中
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 如何使用php文件中的GET来获取我在.js文件中声明的变量
- 如何将模板中的标记脚本移动到.js文件中
- 什么's是连接供应商js文件的最佳方式
- 如何在定义js文件后为外部javascript文件设置变量
- 如何在JS文件中获取资源(.resx)字符串
- 将*.js文件的内容放入Object中
- 如何从onclick函数设置全局变量并将其传递给另一个JS文件
- 导致内容安全策略(CSP)冲突错误的本地jquery.js文件
- 如何使用Gmail运行.js文件
- 如何定义一个模块并使用它来分离js文件
- Angular JS文件上传到托管服务器
- 如何引用HTML中节点模块中的js文件
- 如何将JS文件从其他文件夹链接到页面