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

后端 未结 5 1820
栀梦
栀梦 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条回答
  •  孤独总比滥情好
    2021-02-01 14:02

    Any JavaScript parser should do, acorn mentioned by @cweise is nice because it is fast and has a --silent switch.

    You could also use esvalidate from the npm esprima package: http://ariya.ofilabs.com/2012/10/javascript-validator-with-esprima.html

    $ npm install -g esprima
    $ esvalidate js-file-with-errors.js 
    js-file-with-errors.js:1: Invalid left-hand side in assignment
    

提交回复
热议问题