Search code examples
gulpstylelint

stylelint + gulp doesn't work for subfolders


I use gulp 3.9.1 and stylelint 7.6.0 for SCSS linting. OS is Ubuntu.
A related part of my gulp config looks like this:

var postcss = require('gulp-postcss');
var stylelint = require('stylelint');
var postcssReporter = require('postcss-reporter');
gulp.task('styles', function() {
  ...
  var lintProcessors = [
    stylelint(),
    postcssReporter({ clearMessages: true })
  ];

  gulp.src('app/assets_src/styles/**/*.scss')
    .pipe(postcss(lintProcessors, {syntax: scssSyntax}));
  ...
});

The problem:
Stylelint works great for files like app/assets_src/styles/file.scss
but it doesn't process files in subfolders like: app/assets_src/styles/blocks/home/file.scss Also the weird thing is that in some very rare times it fires once for such nested files, but then stops working again.
I've tried to use such paths:
app/assets_src/styles/**/**/*.scss
/app/assets_src/styles/**/*.scss
'./app/assets_src/styles/**/**/*.scss'
But no luck.

Also using this cli command: stylelint 'app/assets_src/styles/**/*.scss' works good and processes subdirectories. So maybe the issue is related to gulp-postcss plugin.


Solution

  • The answer is - you always have to return a stream from a gulp task, this way gulp understands when the task is terminated.

    Docs: https://github.com/gulpjs/gulp/blob/master/docs/API.md#async-task-support

    Issue discussion thread: https://github.com/postcss/gulp-postcss/issues/107#issuecomment-267168310