0

我的 gulpfile.js 中有这个 gulp 任务,看起来像这样

const runeslint = (cb) => Promise.all(
     gulp.src('./Scripts/**/*.ts')
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError())
).finally(cb);

当使用 gulp runeslint 从命令行运行它时,我会收到一组格式精美的错误消息,但最后它还会打印大约 100 行异常文本。该文本看起来像是由于我的打字稿中的 eslint 标记的错误而引发的异常的字符串表示形式。我想要格式良好的错误输出。我还想要 failAfterError 处理行为,以便如果 runeslint 用作一系列步骤中的一个步骤,那么如果发生 linting 错误,其余步骤将失败。我唯一不想要的是 gulp 打印出异常的 tostring 版本。它没有用,而且完全弄乱了输出日志。

我在https://github.com/adametry/gulp-eslint/blob/master/index.js看到如果发现任何错误,failAfterError 就会抛出。但是,无论我在哪里尝试抑制此异常,要么会破坏 failAfterError 的行为,要么不会抑制错误在我的日志中打印出来。有什么建议么?

我将错误的完整输出放在下面,但我清理了一些公司特定的东西。看,它甚至把这篇文章弄得乱七八糟:)

C:\company-secret-stuff\gulp runeslint
[09:44:46] Using gulpfile ~\source\repos\company-secret-stuff\gulpfile.js
[09:44:46] Starting 'runeslint'...
an error occurred
[09:44:46] Finished 'runeslint' after 64 ms
Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.
[09:44:49]
C:\company-secret-stuff\Scripts\HelloWorld.ts
  2:2   warning  Missing return type on function     @typescript-eslint/explicit-module-boundary-types
  2:28  error    Missing space before opening brace  space-before-blocks
  3:3   warning  Unexpected console statement        no-console

✖ 3 problems (1 error, 2 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.


events.js:292
      throw er; // Unhandled 'error' event
      ^
<ref *1> [PluginError [ESLintError]: Failed with 1 error] {
  plugin: 'gulp-eslint',
  showProperties: true,
  showStack: false,
  __safety: { toString: [Function: bound ] },
  domainEmitter: Transform {
    _readableState: ReadableState {
      objectMode: true,
      highWaterMark: 16,
      buffer: BufferList {
        head: {
          data: File {
            stat: [Stats],
            _contents: [Buffer [Uint8Array]],
            history: [Array],
            _cwd: 'C:\\company-secret-stuff',
            _base: 'C:\\company-secret-stuff\\Scripts',
            _isVinyl: true,
            _symlink: null,
            eslint: [Object]
          },
          next: { data: [File], next: null }
        },
        tail: {
          data: File {
            stat: [Stats],
            _contents: [Buffer [Uint8Array]],
            history: [Array],
            _cwd: C:\\company-secret-stuff',
            _base: 'C:\\company-secret-stuff\\Scripts',
            _isVinyl: true,
            _symlink: null,
            eslint: [Object]
          },
          next: null
        },
        length: 2
      },
      length: 2,
      pipes: [],
      flowing: null,
      ended: false,
      endEmitted: false,
      reading: true,
      sync: false,
      needReadable: true,
      emittedReadable: false,
      readableListening: false,
      resumeScheduled: false,
      errorEmitted: true,
      emitClose: true,
      autoDestroy: true,
      destroyed: true,
      errored: [Circular *1],
      closed: true,
      closeEmitted: false,
      defaultEncoding: 'utf8',
      awaitDrainWriters: null,
      multiAwaitDrain: false,
      readingMore: false,
      decoder: null,
      encoding: null,
      [Symbol(kPaused)]: null
    },
    _events: [Object: null prototype] { prefinish: [Function: prefinish] },
    _eventsCount: 1,
    _maxListeners: undefined,
    _writableState: WritableState {
      objectMode: true,
      highWaterMark: 16,
      finalCalled: false,
      needDrain: false,
      ending: true,
      ended: true,
      finished: false,
      destroyed: true,
      decodeStrings: true,
      defaultEncoding: 'utf8',
      length: 0,
      writing: false,
      corked: 0,
      sync: false,
      bufferProcessing: false,
      onwrite: [Function: bound onwrite],
      writecb: null,
      writelen: 0,
      afterWriteTickInfo: null,
      buffered: [],
      bufferedIndex: 0,
      allBuffers: true,
      allNoop: true,
      pendingcb: 1,
      prefinished: true,
      errorEmitted: true,
      emitClose: true,
      autoDestroy: true,
      errored: [Circular *1],
      closed: true
    },
    allowHalfOpen: true,
    _transform: [Function (anonymous)],
    _flush: [Function (anonymous)],
    [Symbol(kCapture)]: false,
    [Symbol(kTransformState)]: {
      afterTransform: [Function: bound afterTransform],
      needTransform: true,
      transforming: false,
      writecb: null,
      writechunk: null,
      writeencoding: 'utf8'
    }
  },
  domainThrown: false
}
4

0 回答 0