Mozilla Rhino under the hood), we will use it to run Esprima-based syntax validator. For convenience, this will be wrapped as an Ant task called
The example repository demonstrates the usage. After you clone the repo, all you need to do is running:
which will give an output similar to this:
If you open
build.xml, here it is obvious that
jsvalidate task to run the syntax validation on every *.js files under a specific directory. Obviously, you can tweak it to suit your application configuration.
The implementation of
jsvalidate task itself is very simple, just about 50 lines. The spirit its very much the same like the command-line tool
esvalidate (part of Esprima). Given the file set, read the content of every file, check the syntax, and shows the errors (if any). Esprima code is loaded by reading
lib/esprima.js and evaluate it. The included report is minimalistic but informative. If there is at least one syntax error, the task will be marked as failed. As an exercise for the reader, tweak the task so that you can output the validation result in the format of JUnit XML.