简体   繁体   中英

failAfterError gulpEslint

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

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

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.

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