Reputation: 1242
What I would like to do is only run the console.log if all three of the tasks complete successfully. Currently, the js lint item is the only item that seems to have built in functionality to break out if there is an error.
var gulp = require('gulp');
var csslint = require('gulp-csslint');
var eslint = require('gulp-eslint');
var htmlhint = require('gulp-htmlhint');
gulp.task('default', ['lint', 'css', 'html'], function() {
console.log('hi');
});
gulp.task('css', function() {
gulp.src('*.css')
.pipe(csslint())
.pipe(csslint.reporter());
});
gulp.task('lint', function() {
return gulp.src(['**/*.js', '!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.result(function(result) {
console.log('ESLint result: ' + result.filePath);
console.log('# Messages: ' + result.messages.length);
console.log('# Warnings: ' + result.warningCount);
console.log('# Errors: ' + result.errorCount);
}))
.pipe(eslint.failAfterError());
});
gulp.task('html', function() {
return gulp.src('*.html')
.pipe(htmlhint())
.pipe(htmlhint.reporter());
});
Upvotes: 0
Views: 268
Reputation: 8494
Add fail
to the CSS linter's reporter call, .pipe(csslint.reporter('fail'));
and use the HTML linter's failReport htmlhint.failReporter()
vs .pipe(htmlhint.reporter());
.
So in full:
var gulp = require('gulp');
var csslint = require('gulp-csslint');
var eslint = require('gulp-eslint');
var htmlhint = require('gulp-htmlhint');
gulp.task('default', ['lint', 'css', 'html'], function() {
console.log('hi');
});
gulp.task('css', function() {
gulp.src('*.css')
.pipe(csslint())
.pipe(csslint.reporter('fail'));
});
gulp.task('lint', function() {
return gulp.src(['**/*.js', '!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.result(function(result) {
console.log('ESLint result: ' + result.filePath);
console.log('# Messages: ' + result.messages.length);
console.log('# Warnings: ' + result.warningCount);
console.log('# Errors: ' + result.errorCount);
}))
.pipe(eslint.failAfterError());
});
gulp.task('html', function() {
return gulp.src('*.html')
.pipe(htmlhint())
.pipe(htmlhint.failReporter());
});
Upvotes: 1