将 Gulp-TSLint 转换为 Gulp-ESLint

问题描述 投票:0回答:1

我有一个 Gulp 任务需要从

gulp-tslint
更新为
gulp-eslint
,如下所述

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;

我已经将我的 NPM 任务从 TSLint 迁移到 ESLint,但我需要转换最后一个任务,并且我正在努力寻找一个直接的答案:( 我会规定这需要在最后导出为 lintTask,原因如下:/

我已经尝试过 Google TBH,我找到的任何教程都是 JS 相关的,而不是 TS :(

有人可以帮忙吗?

typescript gulp eslint tslint typescript-eslint
1个回答
0
投票

我想我可能已经弄清楚了,对于那些刚开始使用 GULP 的人来说,我这样做了,我的 TS 文件似乎又出现了 lint...

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;
© www.soinside.com 2019 - 2024. All rights reserved.