juanfran / gulp-scss-lint

Gulp plugin to lint scss files with `scss-lint`
113 stars 33 forks source link

failReporter and gulp.watch don't work together #67

Open ehaeusler opened 8 years ago

ehaeusler commented 8 years ago

Hi there,

In my current setup (Gulp 4.0.0-alpha.2) gulp.watch stops working after the first execution if I use failReporter. The task runs successfully, but further changes don't trigger another task. Without the failReporter, the watcher works. I even tried it with the endless option, but that prevents the task from executing entirely (Shell output stops at "Starting 'styles'....).

My gulpfile:

var gulp         = require('gulp'),
    autoprefixer = require('autoprefixer'),
    scss         = require('gulp-sass'),
    postcss      = require('gulp-postcss'),
    scsslint     = require('gulp-scss-lint'),
    sourcemaps   = require('gulp-sourcemaps'),
    importer     = require('sass-module-importer'),
    cleancss     = require('gulp-clean-css'),
    Cachebuster  = require('gulp-cachebust'),
    cachebust    = new Cachebuster();

gulp.task('styles', function ()
{
    return gulp
        .src('scss/**/*.scss')
        .pipe(sourcemaps.init())
        .pipe(scsslint())
        .pipe(scsslint.failReporter())
        .pipe(scss({importer: importer()}))
        .pipe(cachebust.resources())
        .pipe(postcss([autoprefixer({browsers: ['last 2 versions']})]))
        .pipe(cleancss())
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('./styles'))
});

gulp.task('default', gulp.series('styles'));

gulp.task('watch', function ()
{
    return gulp.watch('scss/**/*.scss', gulp.series('styles'));
});
juanfran commented 8 years ago

sorry for waiting.

why do you need failReporter? the purpose of failReporter is fail when there are errors

ehaeusler commented 8 years ago

Thats what I want it to do. If there are errors during linting, the task should fail so you are forced to fix them before recompiling. But if everything is ok, the task should continue like usual. Isn't that how you use failReporter? --- Edit --- Sorry, if that wasn't clear before: This happens when linting is successful. The task just doesn't activate again after further changes.

juanfran commented 8 years ago

I can't reproduce it, sorry. Are you getting any message on the first execution?

dak commented 8 years ago

I ran into the same issue and ended up writing a custom report function to set the process.exitCode to 1 if there is an error:

function scsslint() {
    return gulp.src(paths, {
        since: gulp.lastRun('scsslint')
    })
    .pipe(pi.scssLint({
        config: 'gulp/.scss-lint.yml',
        customReport: (file) => {
            var colors = pi.util.colors;

            if (!file.scsslint.success) {
                process.exitCode = 1;

                pi.util.log(
                    colors.cyan(file.scsslint.issues.length) +
                    ' issues found in ' +
                    colors.magenta(file.path)
                );

                file.scsslint.issues.forEach((issue) => {
                    var severity = issue.severity === 'warning' ? colors.yellow(' [W] ') : colors.red(' [E] ');
                    var linter = issue.linter ? (`${issue.linter}: `) : '';
                    var logMsg = `${colors.cyan(file.relative)}:` +
                        colors.magenta(issue.line) +
                        severity +
                        colors.green(linter) +
                        issue.reason;

                    pi.util.log(logMsg);
                });
            }
        }
    }));
}
gulp.task('styles:watch', () => {
    gulp.watch(paths, options)
    .on('change', gulp.series(
        scsslint,
        // other tasks
    ));
});
juanfran commented 8 years ago

I've made a simple example of what I've tried https://github.com/juanfran/gulp-scss-lint/tree/test-bug/test-bug

ehaeusler commented 8 years ago

I tried your example and don't run into the situation there. Maybe it's caused in combination with one of the other plugins. I'll try to isolate it and provide feedback, if I find something.

@dak If I understand you correctly, your change is based on the situation where errors do happen? Because I get no further execution after the first successfull run.

dak commented 8 years ago

@ehaeusler It should continue to run even if warnings/errors are thrown (it won't stop the next tests from being run either). But if you're using any kind of continuous integration (like Travis CI), it will properly signal to that environment that the test failed (and if you integrate it with GitHub, can allow you to prevent merging commits with errors).