Search code examples
gulpeslint

Gulp Task does not include subfolders


I'm trying to set up a Gulp task for eslint (System: OS Windows 10). But it seems that the src is not being evaluated correctly:

gulp.task('lint-app-basic-an', function() {
    gulp.src('src/main/webapp/app-basic-an/**/*.js')
        .pipe(eslint({
            configFile: '.eslintrc.js'
        }))
        .pipe(eslint.format())
        .pipe(eslint.failAfterError());
});

There are several subfolders underneath src/main/webapp/app-basic-an, e.g.

src/main/webapp/app-basic-an/components/page-header/page-header.component.js

If I create a lint error in said JS-File, it is ignored by the linter. If I specify the path 1 level more in the tasks .src-function like

gulp.src('src/main/webapp/app-basic-an/components/**/*.js')

It suddenly works, which makes no sense to me, I thought "**/" meant zero or more subdirectories?


Solution

  • Gulp executes its tasks in an asynchronous manner. For gulp to be able to know that some task has finished, the tasks needs to do one of the following:

    • return stream (e.g. the one created by gulp.src) on which gulp can listen for end event,
    • return q promise or
    • call callback function passed as task function argument

    If the task does not accept arguments and does not return promise or stream, gulp considers that task synchronous (i.e. it is finished once the function call returns). Once all tasks are finished, the execution stops... hence if you have some async processing, it will never finish (or worse - it might end at a random point).