2

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.

3
  • 2
    look at Gulp, gulp jshint Commented May 19, 2015 at 9:55
  • Use CoffeeScript :) It compiles to JSlint-proof javascript code, and the compiler will stop and tell you if there's any syntax errors. Commented May 19, 2015 at 10:13
  • Don't confuse "syntactically correct" for "compiles properly", or syntax-checking for static-analysis. Commented May 19, 2015 at 10:31

1 Answer 1

1

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 
});
Sign up to request clarification or add additional context in comments.

1 Comment

You may also want to look at ESLint as an alternative to JSLint. You can find the gulp plugin here: github.com/adametry/gulp-eslint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.