简体   繁体   中英

How to log a message when jshint task runs and everything is correct?

I am working on a Gulp file and I am doing the task for jshint to check my code.

gulp.task('lint', function () {
    return gulp.src(['public/**/*.js', 
                     '!public/vendor/*.js', '!public/app.min.js', '!public/fonts/*.*',
                     '!public/favico.png', '!public/templates.js'])
            .pipe(jshint())
            .pipe(jshint.reporter( 'default' ));
});

I just fix some errors I had in the code but the console/terminal didn't print anything to know if now everything is correct.

How should I do that ?

As said in github project page,

you can create a custom reporter that will print every error.

code is like this:

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

    var myReporter = map(function (file, cb) {
      if (!file.jshint.success) {
        console.log('JSHINT fail in '+file.path);
        file.jshint.results.forEach(function (err) {
          if (err) {
            console.log(' '+file.path + ': line ' + err.line + ', col ' + err.character + ', code ' + err.code + ', ' + err.reason);
          }
        });
      }
      cb(null, file);
    });

gulp.task('lint', function () {
    return gulp.src(['public/**/*.js', 
                     '!public/vendor/*.js', '!public/app.min.js', '!public/fonts/*.*',
                     '!public/favico.png', '!public/templates.js'])
            .pipe(jshint())
           .pipe(myReporter);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM