如何仅从命令行检查JavaScript代码是否存在语法错误? [英] How can I check JavaScript code for syntax errors ONLY from the command line?
问题描述
可以在IDE中或使用来检查JavaScript程序是否存在错误.在线网络应用,但我正在寻找一种单独检测语法错误的方法.
JavaScript programs can be checked for errors in IDEs or using online web apps but I'm looking for a way to detect syntax errors alone.
我已经尝试过JSLint和JSHint并查看了它们的选项,但是我无法找到一种组合来排除警告和
I've tried JSLint and JSHint and looked at their options but I haven't been able to find a combination that would exclude warnings and just shows the syntax errors.
如何从命令行检查JavaScript代码仅语法错误?
How do I check JavaScript code for syntax errors only from the command line?
推荐答案
解决方案是启用jshint的--verbose
选项,该选项显示错误或警告代码(例如,E020
表示Expected '}' to match '{'
或W110
表示Mixed double and single quotes
),然后grep仅用于错误:
The solution is to enable jshint's --verbose
option, which shows the error or warning code (e.g. E020
for Expected '}' to match '{'
or W110
for Mixed double and single quotes
), then grep for errors only:
jshint --verbose test.js | grep -E E[0-9]+.$
这篇关于如何仅从命令行检查JavaScript代码是否存在语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!