Git Product home page Git Product logo

Comments (11)

UltCombo avatar UltCombo commented on August 15, 2024

What gulp-watch version are you using? There are huge differences between 2.x, 3.x and 4.x.

from gulp-jscs.

Tomalak avatar Tomalak commented on August 15, 2024
  "devDependencies": {
    "gulp": "^3.8.10",
    "gulp-jscs": "^1.4.0",
    "gulp-jshint": "^1.9.0",
    "gulp-watch": "^4.1.0",
    "jshint-stylish": "^1.0.0",
    "lazypipe": "^0.2.2"
  }

from gulp-jscs.

UltCombo avatar UltCombo commented on August 15, 2024

Currently, gulp-jscs only emits errors when the readable stream that is being piped into it ends, and your code is using gulp-watch's "endless stream" mode. I believe the callback mode is more suited for your needs:

gulp.task('watch', function() {
    return watch(paths.scripts, function(files) {
        files
            .pipe(jscsRunner)
            .pipe(jshintRunner)
            .pipe(jshint.reporter('default'));
    });
});

from gulp-jscs.

Tomalak avatar Tomalak commented on August 15, 2024

@UltCombo Sounds good, but unfortunately doesn't work.

I think that is because files (file, really, in the callback there only ever is exactly one) is not a stream of vinyl objects, it's a single object. However, jscs expects a stream and crashes when it gets a file.

from gulp-jscs.

UltCombo avatar UltCombo commented on August 15, 2024

Oh I see, my bad. I thought the argument was still a stream (as it was in 3.x) because in my real use cases I still use gulp-batch (which used to be part of gulp-watch prior to v4.x, and now must be explicitly included):

var batch = require('gulp-batch');
gulp.task('watch', function() {
    return watch(paths.scripts, batch(function(files) {
        return files
            .pipe(jscsRunner)
            .pipe(jshintRunner)
            .pipe(jshint.reporter('default'));
    }));
});

I've hastily adapted this code removing gulp-batch for the previous comment without knowing that the argument type has changed. The code with gulp-batch should work though. There are cleaner ways around this, of course -- I'll post one when I get home.

from gulp-jscs.

Tomalak avatar Tomalak commented on August 15, 2024

I'll wait. I've tried (and failed) to construct a single-object readable stream from the file, but my node experience so far is rather limited.

from gulp-jscs.

UltCombo avatar UltCombo commented on August 15, 2024

You can use stream-array (or event-stream's readArray) to make things easier:

var streamify = require('stream-array');
gulp.task('watch', function() {
    return watch(paths.scripts, function(file) {
        streamify([file])
            .pipe(jscsRunner)
            .pipe(jshintRunner)
            .pipe(jshint.reporter('default'));
    });
});

from gulp-jscs.

Tomalak avatar Tomalak commented on August 15, 2024

Now we're getting somewhere.

Your suggestion still isn't complete, though. jscs throws errors when it finds style violations and these errors need to be handled or gulp will crash.

Here is what I use now.

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var watch = require('gulp-watch');
var lazypipe = require('lazypipe');
var streamify = require('stream-array');

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

var lintTasks = lazypipe()
    .pipe(jshint, {
        // ...
    })
    .pipe(jshint.reporter, 'jshint-stylish');

var jscsTasks = lazypipe()
    .pipe(jscs, {
        // ...
    });

gulp.task('watch', function() {
    return watch(paths.scripts, function(file) {
        streamify([file])
        .pipe(jscsTasks())
        .on('error', function (error) {
            console.log(error.toString());
        })
        .emit('end');
    })
    .pipe(lintTasks());
});

from gulp-jscs.

UltCombo avatar UltCombo commented on August 15, 2024

Oh yes, that's another detail I forgot -- gulp-batch wraps the callback in a domain so the error handler wouldn't be necessary if you were using gulp-batch.

Also should note that you won't need to use the callback style nor catch errors after #66 is merged.

from gulp-jscs.

UltCombo avatar UltCombo commented on August 15, 2024

Correction: if you were using gulp-batch the error would be suppressed by default, you'd need to supply an error handle to gulp-batch in order to log the error message as well.

from gulp-jscs.

Tomalak avatar Tomalak commented on August 15, 2024

Nice. For the moment I have something that works and I'll follow #66.

from gulp-jscs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.