How can I check JavaScript code for syntax errors ONLY from the command line?

后端 未结 5 1884
栀梦
栀梦 2021-02-01 13:40

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.

I\'ve tried JSLint and

5条回答
  •  旧时难觅i
    2021-02-01 13:55

    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]+.$
    

提交回复
热议问题