panuhorsmalahti / gulp-tslint

TypeScript linter plugin for Gulp
MIT License
118 stars 44 forks source link

Gulp examples do not correctly return the stream #138

Closed gwicksted closed 6 years ago

gwicksted commented 6 years ago

gulp-tslint version: (latest source #53534f8) 8.1.2 tslint version: 5.8.0 gulp: 3.9.1 node: 9.0.0 Operating system: Windows 10 x64

Example gulp configuration -- here are just 2 examples from the readme:

gulp.task("tslint", () =>
    gulp.src("source.ts")
        .pipe(tslint({
            formatter: "verbose"
        }))
        .pipe(tslint.report())
);

gulp.task("invalid-noemit", () =>
    gulp.src("input.ts")
        .pipe(tslint({
            formatter: "prose"
        }))
        .pipe(tslint.report({
            emitError: false
        }))
);

Corrected documentation (just the return statement added):

gulp.task("tslint", () =>
    return gulp.src("source.ts")
        .pipe(tslint({
            formatter: "verbose"
        }))
        .pipe(tslint.report())
);

gulp.task("invalid-noemit", () =>
    return gulp.src("input.ts")
        .pipe(tslint({
            formatter: "prose"
        }))
        .pipe(tslint.report({
            emitError: false
        }))
);

Error console output:

[12:40:13] Using gulpfile
[12:40:13] Starting 'lint'...
[12:40:14] Finished 'lint' after

long pause here

Reasoning behind the change:

If you don't return the stream, gulp expects the callback to be called so it ends up waiting unnecessarily after tslint completes.

panuhorsmalahti commented 6 years ago

() => gulp.src("input.ts") is a ES6 short-hand for () => { return gulp.src("input.ts"). Your examples are not syntactically correct.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

gwicksted commented 6 years ago

Can't believe I missed that! My test had the {}. Sorry! My bad.