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

后端 未结 5 1829
栀梦
栀梦 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 13:48

    I use acorn:

    $ acorn --silent tests/files/js-error.js; echo $?
    Unexpected token (1:14)
    1
    
    $ acorn --silent tests/files/js-ok.js; echo $?
    0
    

    Install via: npm -g install acorn.

提交回复
热议问题