Eslint --fix抑制错误,但实际上并未更改文件

时间:2019-03-05 21:19:22

标签: gulp eslint

我正在使用gulp和eslint构建代码,当我运行皮棉时,我有很多缩进/间距错误。我将修复标记添加到了gulpfile中:

gulp.task('lint', function() {
    return gulp
        .src([config.tap.src])
        .pipe(eslint({
            fix:true,
            envs: ['jquery', 'browser']
          }
        ))
        .pipe(eslint.format())
        .pipe(eslint.failAfterError());
});

,错误消失了。但是,我的文件似乎有和以前一样的不正确缩进;根据文档修复应该更改我的文件吗?我还需要其他参数来修复这些更改吗?

例如,我得到了错误:

  12:1   error  Expected indentation of 6 spaces but found 12                    indent

,但修复缩进后仍然相同。 有人有解决方案吗?

1 个答案:

答案 0 :(得分:0)

事实证明,使用eslint,您需要指定修复程序的保存位置。其他SO线程建议使用gulp.dest('.')gulp.dest('./'),但是这些线程为我创建了新文件夹,而不是覆盖原始文件夹。我在下面发布的内容对我有用。

   return gulp
        .src([config.src])
        .pipe(eslint({
            fix:true
          }
        ))
        .pipe(eslint.format())
        .pipe(
          gulp.dest(function (file) {
            return file.base;
          })
        )
        .pipe(eslint.failAfterError());