Reputation: 9206
One of the great features of PHP was php -l
, which checked all the code for syntax without executing it. Is there a similar way to do so for JavaScript in AngularJS? That is, in addition to my test suite coverage (which may not be 100%, and won't be instant if it is), is there a way to (perhaps using Node) check that all of my code compiles properly etc.
Upvotes: 2
Views: 2702
Reputation: 5981
By using node.js and a build tool called Gulp, you can easily set up and manage an automatic code validation. In fact, you can automate linting, minification and copying of JavaScript files, bundling/concat, renaming, testing, test code coverage etc etc.. List goes on.
How to install and use gulp is documented on their Github repository, and there is even a sample file to get you started. Smahing Magazine have a detailed tutorial about using Gulp as a build/test tool aswell.
Lint JavaScript files example:
// Gulpfile.js
var gulp = require('gulp'),
jshint = require('gulp-jshint');
gulp.task('js-lint', function () { // Task name
return gulp.src('js/*.js') // source files
.pipe(jshint()) // library
.pipe(jshint.reporter('default')) // reporter
});
Upvotes: 1