gulp-stylelint icon indicating copy to clipboard operation
gulp-stylelint copied to clipboard

gulp-stylelint failing out of gulp process on error

Open matthewmcvickar opened this issue 4 years ago • 5 comments

When I have a stylelint error, it is failing out of gulp, which means I have to completely restart Gulp every time I make a mistake.

(At first I thought this was a gulp-notify issue, but it persists when gulp-notify is disabled.)

My gulp task:

// Build CSS.
const compileCSS = () => {
  const sassOptions = {
    includePaths: ['node_modules']
  }

  const stylelintOptions = {
    reporters: [
      {
        formatter: 'string',
        console: true
      }
    ]
  }

  return gulp.src(paths.css.src)
    .pipe(stylelint(stylelintOptions))
    .pipe(gulpif(isDev, sourcemaps.init()))
    .pipe(sass(sassOptions))
    .on('error', notify.onError((error) => {
      return error.message;
    }))
    .pipe(postcss([ autoprefixer() ]))
    .pipe(gulpif(isDev, sourcemaps.write()))
    .pipe(gulpif(!isDev, rename({ suffix: '.min' })))
    .pipe(gulp.dest(paths.css.dest))
    .pipe(browserSyncServer.stream())
}

And the terminal output:

[16:02:18] Starting 'compileCSS'...
[16:02:19]

_src/css/global/_images.scss
 90:1   ✖  Expected empty line before comment   scss/double-slash-comment-empty-line-before
 90:13  ✖  Expected a space after //            scss/double-slash-comment-whitespace-inside



[16:02:19] 'compileCSS' errored after 884 ms
[16:02:19] Error in plugin "gulp-stylelint"
Message:
    Failed with 2 errors
Details:
    domainEmitter: [object Object]
    domainThrown: false

This should show a notification on my machine, but it doesn't; it's just failing in the terminal.

I am running the latest of all relevant packages as of this writing:

  • gulp 4.0.2
  • gulp-stylelint 13.0.0
  • stylelint-scss 3.17.2

matthewmcvickar avatar Apr 29 '20 23:04 matthewmcvickar

I'm also having the same issue.

gulp.task('sass:stylelint', function () {
  var src = config.sass.watchSrc;
  if (config.sass.lint.extraSrc) {
    src = src.concat(config.sass.lint.extraSrc);
  }
  return gulp.src(src)
    .pipe(gulp.$.stylelint({
      reporters: [
        {
          formatter: 'string', 
          console: true,
          failAfterError: false,
        }

      ]
    }))
});

gulp 4.0.2 gulp-stylelint 13.0.0 stylelint-scss 3.18

finteractive avatar Feb 17 '21 22:02 finteractive

Getting the same error as well. Running stylelint with the CL runs just fine. Using the default gulp-stylelint implementation from the readme. Stylelint config just the default as well.

gulp 4.0.2 gulp-stylelint 13.0.0 stylelint 13.10.0 stylelint-config-standard 20.0.0

danparm avatar Feb 19 '21 14:02 danparm

Just noticed the same. What's up?

ronilaukkarinen avatar Apr 01 '21 11:04 ronilaukkarinen

By setting the failAfterError option to false of gulpStylelint got it working fine. Appears that Stylelint considers any violation as an error. Which then causes the task to fail. I don't agree with that as it prevents the linting of files. My setup generates a JSON file which is then rendered as a report in the browser. Even if Stylelint wants to say that a violation is an error, gulp-stylelint should disregard that. Please let me know what I'm missing here. Is there some config option in Stylelint to prevent a file with violations to be considered "errored?"

danparm avatar Apr 02 '21 16:04 danparm

Nothing to add other than to say I'm also running into the same issue. My setup is the same as @danparm . Setting failAfterError to false also worked for me.

mattpfeffer avatar Aug 08 '21 11:08 mattpfeffer