Nazir Doğan Code Blog

Integrating Jshint in Ionic Framework

| Comments

if you are developing ionic apps.  you can see build system in your projects which is  Gulp . it's not ionic specific but it's used in ionic projects and many other project ,its so similar to Grunt.

in this post ,I write about how can save time  with linting javascript files  in your ionic project.

 

Let's create an ionic project

//
ionic start jshint-ionic

//in your project folder

 npm install


After creating an ionic project for using JSHint ,we must load gulp-jshint and  jshint-stylish  from npm.

//


npm install gulp-jshint jshint-stylish --save-dev


//

We installed gulp-jshint and jshint-stylish. jshint-stylish is not necessary but make output looks good.

After that we must edit gulpfile.js include this line of code.

//

var  jshint = require('gulp-jshint');

//

then add gulp  task

//


gulp.task('lint', function() {
  return gulp.src('./www/js/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'));
});


//

 

Now you can run  gulp lint  command  see syntax and logical error.

if you want to watch jshint  then add this line in "watch" task

//


gulp.task('watch', function() {
  gulp.watch(paths.sass, ['sass']);

    gulp.watch('./www/js/app/*.js', ['lint']);
});

//

you dont write gulp lint command. if you serve your project jshint works automatically.

 

 

 

 

Comments