本文介绍了gulp-jshint:如何使构建失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



根据我可以使用fail记者。



然而,以下内容不起作用: p>

  gulp.task(lint,function(){
return gulp.src(JS_SOURCES)
。 pipe(jshint())
.pipe(jshint.reporter(jshint-stylish))
.pipe(jshint.reporter(fail));
});

即使JSHint中存在错误,上述任务始终返回退出代码0。 >

我在使用gulp 3.8.10和gulp-jshint 1.9.0。



gulp-jshint 和 ......但根据这些讨论,我收集了上面的代码应该与最新版本的gulp和gulp-jshint一起工作。然而,它不... ...

有没有人想出如何使用gulp-jshint正确构建失败?

解决方案

TLDR;
直到GulpJS在稳定版本中提供了一个很好的解决方案之前,请使用。



何使用他自己的过滤器创建解决方法:

  var map = require('map-stream'); 
var exitOnJshintError = map(function(file,cb){
if(!file.jshint.success){
console.error('jshint failed');
process。退出(1);
}
});
gulp.task('lint',function(){
gulp.src('example.js')
.pipe(jshint())
.pipe(jshint。记者('jshint-stylish'))
.pipe(exitOnJshintError);
});

长答案

这个问题已作为GitHub上的问题发布:。请特别注意。



他建议的解决方案是添加自己的过滤器,并在出现提示错误时执行 process.exit(1); ,看起来像这样:

  var map = require('map-stream'); 
var exitOnJshintError = map(function(file,cb){
if(!file.jshint.success){
console.error('jshint failed');
process。退出(1);
}
});

gulp.task('lint',function(){
gulp.src('example.js')
.pipe(jshint())
。 pipe(jshint.reporter('jshint-stylish'))
.pipe(exitOnJshintError);
});

这个问题与另一个问题有关。
他们在这里说的基本上是Gulp应该关注构建失败。
这会导致另一个已经在GulpJS上报告的问题:。
后者已经修复,Gulp JS版本可以在以下网址上查看:。



所以,我们必须等待它被释放......



我已经实现了它我的。


I want my Gulp build to fail, if there are errors in JSHint.

According to the documentation of gulp-jshint I can use the "fail reporter".

However the following does not work:

gulp.task("lint", function() {
     return gulp.src(JS_SOURCES)
        .pipe(jshint())
        .pipe(jshint.reporter("jshint-stylish"))
        .pipe(jshint.reporter("fail"));
});

The task above always returns with exit code 0, even when there are errors in JSHint.

I am using gulp 3.8.10 and gulp-jshint 1.9.0.

There are discussions in the github issues of gulp-jshint here and here ... but according those discussions I gather that above code should work with the latest versions of gulp and gulp-jshint. However it does not ...

Has anybody figured out how to fail the build properly with gulp-jshint?

解决方案

TLDR;Until GulpJS comes with a good solution in a stable release, use the workaround as suggested by Bahmutov on GitHub.

He creates a workaround, using his own filter:

var map = require('map-stream');
var exitOnJshintError = map(function (file, cb) {
  if (!file.jshint.success) {
    console.error('jshint failed');
    process.exit(1);
  }
});
gulp.task('lint', function() {
  gulp.src('example.js')
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(exitOnJshintError);
});

Long answer

This question has been posted as an issue on GitHub: How to fail gulp build? #6 . Pay special attention to Bahmutov's comment.

The solution (hack) he proposes is to add his own filter and do a process.exit(1); when there are hinting errors, which looks like this:

var map = require('map-stream');
var exitOnJshintError = map(function (file, cb) {
  if (!file.jshint.success) {
    console.error('jshint failed');
    process.exit(1);
  }
});

gulp.task('lint', function() {
  gulp.src('example.js')
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(exitOnJshintError);
});

This issue links to another issue Plugin doesn't fail build #10.What they say here basically, is that Gulp should take care of the build failing.This results in another issue which has been reported on GulpJS: Controlling failing builds #113. Which on his turn has been move to "finish then fail" #20.The latter one has been fixed and the Gulp JS release can be tracked on: changing this #347.

So, we'll have to wait for it to be released...

In the mean time, we can use the workaround as mentioned at the top of my post in the TLDR;

I've implemented it my gulpfile.js in task scripts-app.

这篇关于gulp-jshint:如何使构建失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 14:30