failAfterError gulpEslint

413 views Asked by At

Hello I have the following gulp task that lints the solution and fails after any error in the linting process, I would like it to fail with text and not just fall over in a heap, I am not sure how to implement this. Any help would be appreciated.

gulp.task('lint-solution', function(done){
log('Linting solution')
return gulp.src(['../CRMPortal/**/*.js','../Common/**/*.js','!../Common/scripts/**/*','!../node_modules/**','!../CRMPortal/dist/**','!../CRMPortal/gulpfile.js'])
  .pipe($.eslint({configFile: ".eslintrc.json"}))
  .pipe($.eslint.format(
    reporter, function(results){
      fs.writeFileSync(path.join(__dirname,'report.html'), results);
    }
  ))
  .pipe($.eslint.failAfterError()); <-- I want text I provide to be printed on error here should that be the case , not just the error
})

At the moment (obviously) all I get is :

Message:
Failed with 1 error
1

There are 1 answers

0
Sven Schoenung On

You cannot change this line:

Message:

This line is printed by gulp itself whenever an error is encountered. You cannot suppress it unless you suppress the error itself, in which case your task won't fail if an error is encountered.

You can change this line however:

Failed with 1 error

This line is stored on the error object that is emitted by gulp-eslint. You can access the error object by registering an .on('error') handler on your stream and then modify the message if the error was emitted by gulp-eslint:

.pipe($.eslint.failAfterError()) 
.on('error', function(err) {
  if (err.plugin === 'gulp-eslint') {
    err.message = 'Oops';
  }
});

This outputs the following:

Message:
    Oops