Convert Gulp-TSLint to Gulp-ESLint

111 views Asked by At

I have a Gulp task that needs updating from gulp-tslint to gulp-eslint as outlined below

const { src } = require('gulp');
const config = require('./config');

const plugins = require('gulp-load-plugins')();
const plumber = require('./plumber-wrapper');
const mergeStream = require('merge-stream');
const gulpTsLint = require('gulp-tslint');
const tslint = require('tslint');

function lintTask () {

    const { srcDir, jsDir, sassFiles } = config
    const tsLintProgram = tslint.Linter.createProgram('./tsconfig.json')
    const typeScript = src(`${srcDir}${jsDir}**/*.ts`)

        .pipe(plumber())
        // lint according to rules defined in `tslint.json`
        .pipe(
            gulpTsLint({
                formatter: 'verbose',
                /**
                 * type-checked rules require a TypeScript `program` object.
                 * ensure 'Linter.createProgram' is called inside the gulp task else the
                 * contents of the files will be cached if this tasks is called again,
                 * e.g. as part of a `watch` task
                 */
                program: tsLintProgram
            })
        )
        .pipe(gulpTsLint.report());

    const sass = src(`${srcDir}${sassFiles().all}`)
        .pipe(plumber())
        // lint according to rules defined in `.stylelintrc`
        .pipe(
            plugins.stylelint({
                failAfterError: true,
                reporters: [
                    {
                        formatter: 'string',
                        console: true
                    }
                ],
                debug: true
            })
        );

    return mergeStream([typeScript, sass]);

};

module.exports = lintTask;

I have already migrated my NPM Tasks away from TSLint to ESLint, but I need to convert this last one and I'm struggling with a straight answer :( I would stipulate that this needs to be exported as lintTask at the end, for reasons :/

I have tried Google TBH, any tutorials I do find are JS related, not TS :(

Would someone be able to help?

1

There are 1 answers

0
Takuhii On

I think I may have figured it out, for those starting out in GULP, I did this and my TS files seem to lint again...

const { src } = require('gulp');
const config = require('./config');

const plugins = require('gulp-load-plugins')();
const plumber = require('./plumber-wrapper');
const mergeStream = require('merge-stream');
const eslint = require('gulp-eslint');

function lintTask () {

    const { srcDir, jsDir, sassFiles } = config
    const typeScript = src(`${srcDir}${jsDir}**/*.ts`)
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError());

    const sass = src(`${srcDir}${sassFiles().all}`)
        .pipe(plumber())
        // lint according to rules defined in `.stylelintrc`
        .pipe(
            plugins.stylelint({
                failAfterError: true,
                reporters: [
                    {
                        formatter: 'string',
                        console: true
                    }
                ],
                debug: true
            })
        );
    return mergeStream([typeScript, sass]);
};

module.exports = lintTask;