0

I have the following (simplified) set-up in my gulpfile:

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var watch = require('gulp-watch');

var paths = {
        scripts: ['js/*.js']
    }    
var jscsRunner = jscs({
        disallowMixedSpacesAndTabs: true // etc
    });    
var jshintRunner = jshint({
        browser: true // etc
    });

// this outputs messages from jshint no problem
gulp.task('jshint', function() {
    return gulp.src(paths.scripts)
    .pipe(jshintRunner)
    .pipe(jshint.reporter('default'));
});

// this outputs messages from jscs no problem
gulp.task('jscs', function() {
    return gulp.src(paths.scripts)
    .pipe(jscsRunner);
});

// this only outputs messages from jshint
gulp.task('watch', function() {
    return watch(paths.scripts)
    .pipe(jscsRunner)
    .pipe(jshintRunner)
    .pipe(jshint.reporter('default'));
});

My problem is - as indicated - that in the watch task no output is generated from jscs, even though the pipeline is essentially exactly the same as in the jscs task, where it works as expected.

(I'm running this on Windows.)

EDIT: This issue has been reproduced and discussed here: https://github.com/jscs-dev/gulp-jscs/pull/66

Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • What gulp-watch version are you using? There are huge differences between 2.x, 3.x and 4.x. – Fabrício Matté Feb 02 '15 at 23:09
  • I really wonder why this was downvoted. – Tomalak Sep 25 '15 at 08:30
  • I'm not sure, but was it perhaps because gulp-jscs now [supports reporters](https://github.com/jscs-dev/gulp-jscs/pull/66), and the way to use it has changed (as well as the [documentation](https://github.com/jscs-dev/gulp-jscs#usage))? – Fabrício Matté Sep 29 '15 at 00:34
  • @FabrícioMatté Sure, but that's the case all the time on SO. Questions and answers go out of date (or, to put it differently, are relevant to a version that is no longer in common use). Whoever downvoted this must have had a better reason than "this is no longer an issue". – Tomalak Sep 29 '15 at 08:46
  • That's true, I was just trying to guess. Anyway, voting is an anonymous process which instigates people to vote without requiring any particular reason or burden. I'd usually get a few revenge downvotes on my zero-scored questions when I was more active at participating/moderating SO, for instance. Sadly, there is not much to be done as votes are anonymous and don't require a proper reason to be casted. – Fabrício Matté Sep 29 '15 at 16:45

1 Answers1

0

I was able to take your script, clean it up a bit, refactor some code and I was able to get it to work on my machine:

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');

var paths = {
        scripts: ['js/*.js']
    }    

// this outputs messages from jshint no problem
gulp.task('jshint', function() {
    return gulp.src(paths.scripts)
        .pipe(jshint({browser: true}))
        .pipe(jshint.reporter('default'));
});

// this outputs messages from jscs no problem
gulp.task('jscs', function() {
    return gulp.src(paths.scripts)
    .pipe(jscs({ disallowMixedSpacesAndTabs: true }));
});

// this only outputs messages from jshint
gulp.task('watch', function() {
    return gulp.watch(paths.scripts,['jscs','jshint']);
});

A couple things to note:

  1. As of today, as far as I know, watch is now built into gulp, so no need to require gulp-watch. I run gulp version 3.8.11 on my machine and the above script worked fine and I don't have any module named 'gulp-watch' installed on my machine. So I would update to the latest version of gulp and remove the gulp-watch require from your script and from your package.json.
  2. If you want, you could put your options for jshint and jscs into a separate files, and include the path to those files as a parameter to jshint and jscs respectively.
  3. Other than the refactoring I did, the code worked as expected, so I'm unsure as to what exactly was incorrect in your code, but since I'm new to gulp it's difficult for me to speculate as to what may have been wrong with the daisy chained pipe calls you were making in the watch statement.
Anil
  • 2,539
  • 6
  • 33
  • 42
  • Also wanted to mention that I began working on a script that works very similar to yours, which is why I was able to refactor your code to work as it is very similar to my script. I'm facing a different issue in my script, but you're welcome to use the improvements I have in my script for yours if you so choose: http://stackoverflow.com/questions/30418131/issue-with-task-not-executing-when-using-gulp-with-run-sequence – Anil May 23 '15 at 23:10