juanfran / gulp-scss-lint

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

How to stop task on error's and warning but continue with watch #44

Closed Evaske closed 7 years ago

Evaske commented 9 years ago

Hey,

I'm trying to achieve the following:

Run gulp watch. When it notices a change in an scss file, then it runs scss-lint followed by gulp-sass. I want it so that if any errors or warnings are returned from gulp-scss-lint they are displayed in the CMD window and then gulp-scss won't run and watch will continue.

Gulp-scss should only run when there are no warnings or errors output from gulp-scss-lint.

Is this possible in its current form?

juanfran commented 9 years ago

hi!

Is this what you want?

var sass = require('gulp-sass');
var gulpif = require('gulp-if');

gulp.task('lint', function() {
    var condition = function(file) {
        return !(file.scsslint.errors || file.scsslint.warnings);
    };

    return gulp.src('**/*.scss')
        .pipe(scsslint())
        .pipe(gulpif(condition, sass()));
});
Evaske commented 9 years ago

How would this work in the fact that I don't want to be running sass() on every .scss file? Just the one file. Also, at the moment it runs that condition check for every scss file there is, so it will keep compiling multiple times until it hits an error. What I want is it to completely run through all the files with scss-lint and then run scss() if there are no errors found.

So basically want this to occur:

//  SCSS Linting. Ignores the reset file
gulp.task('scss-lint', function () {
  gulp.src([styleSheets + '**/*.scss', '!' + styleSheets + '**/_reset.scss'])
  .pipe(scssLint())
});

The scss-lint task runs, and if any Errors or Warnings occur, then nothing else happens. If no errors or warnings occur then I want it to run scss(). I don't want this to be on a file by file basis which is what happens with your code above but rather it lints all the SCSS files and then if it's successfully on all of them, then it runs the scss() on just the main styles.scss file.:

gulp.task('sass', function () {
  gulp.src(styleSheets + 'styles.scss')
  .pipe(sass({
    outputStyle: 'compressed'
  }))
  .on("error", notify.onError(function (error) {
    return error.message;
  }))
  .pipe(gulp.dest(styleSheetsDist))
  .pipe(notify({ message: "Stylesheets Compiled", title: "Stylesheets" }))
});
juanfran commented 9 years ago
gulp.task('scss-lint', function() {
    return gulp.src('**/*.scss')
        .pipe(scsslint())
        .pipe(scsslint.failReporter());
});

gulp.task('sass', ['scss-lint'], function() {
    return gulp.src('**/*.scss')
        .pipe(scss());
});