0

您好,我有以下 gulp 任务对解决方案进行 linting 并在 linting 过程中出现任何错误后失败,我希望它因文本而失败,而不仅仅是在一堆中摔倒,我不知道如何实现这一点。任何帮助,将不胜感激。

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
})

目前(显然)我得到的只是:

Message:
Failed with 1 error
4

1 回答 1

1

您不能更改此行:

Message:

每当遇到错误时,gulp 都会打印此行。除非您抑制错误本身,否则您无法抑制它,在这种情况下,如果遇到错误,您的任务不会失败。

但是,您可以更改此行:

Failed with 1 error

此行存储在由 发出的错误对象上gulp-eslint。您可以通过在流上注册处理程序来访问错误对象.on('error'),然后如果错误由以下方式发出,则修改消息gulp-eslint

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

这将输出以下内容:

Message:
    Oops
于 2016-12-19T12:02:53.833 回答