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 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.
How do I check JavaScript code for syntax errors only from the command line?
An exception caused by the incorrect use of a pre-defined syntax. Syntax errors are detected while compiling or parsing source code. For example, if you leave off a closing brace ( } ) when defining a JavaScript function, you trigger a syntax error.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With