Javascript 如何抑制linting异常

Javascript 如何抑制linting异常,javascript,gulp,eslint,gulp-eslint,Javascript,Gulp,Eslint,Gulp Eslint,我的gulpfile.js中有一个类似于以下内容的gulp任务 const runeslint = (cb) => Promise.all( gulp.src('./Scripts/**/*.ts') .pipe(eslint()) .pipe(eslint.format()) .pipe(eslint.failAfterError()) ).finally(cb); 当使用gulpruneslint从命令行运行它时,我会得到一组

我的gulpfile.js中有一个类似于以下内容的gulp任务

const runeslint = (cb) => Promise.all(
     gulp.src('./Scripts/**/*.ts')
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError())
).finally(cb);
当使用gulpruneslint从命令行运行它时,我会得到一组格式良好的错误消息,但最后它还会打印大约100行异常文本。文本看起来像异常的字符串表示形式,该异常是由于我的typescript中eslint标记的错误而引发的。我想要格式良好的错误输出。我还需要failAfterError处理行为,以便如果runeslint用作一系列步骤中的一个步骤,那么如果发生linting错误,其余步骤将失败。我唯一不想让gulp打印出异常的tostring版本。它没有用处,而且会把输出日志弄得乱七八糟

我在failAfterError中看到,如果发现任何错误,就会抛出错误。但是,无论我在哪里尝试抑制该异常,要么破坏failAfterError的行为,要么不抑制在日志中打印出的错误。有什么建议吗

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

C:\company secret stuff\gulp runeslint
[09:44:46]使用gulpfile~\source\repos\company secret stuff\gulpfile.js
[09:44:46]正在启动“runeslint”。。。
发生了一个错误
[09:44:46]在64毫秒后完成“runeslint”
警告:在eslint插件React设置中,React版本设置为“检测”,但未安装“React”软件包。假设最新版本的皮棉。
[09:44:49]
C:\company secret stuff\Scripts\HelloWorld.ts
2:2警告:函数@typescript eslint/显式模块边界类型上缺少返回类型
2:28错误在打开支撑之前缺少空格块之前的空格
3:3警告意外控制台语句无控制台
✖ 3个问题(1个错误,2个警告)
1个错误和0个警告可能可通过“---fix”选项修复。
events.js:292
投掷者;//未处理的“错误”事件
^
[插件错误[ESLintError]:失败,出现1个错误]{
插件:'gulp eslint',
showProperties:true,
showStack:false,
__安全性:{toString:[函数:绑定]},
域发射器:变换{
_readableState:readableState{
objectMode:true,
高水位:16,
缓冲区:缓冲区列表{
负责人:{
数据:文件{
stat:[Stats],
_内容:[缓冲区[Uint8Array]],
历史记录:[数组],
_cwd:'C:\\公司机密资料',
_base:'C:\\company secret stuff\\Scripts',
_是的,
_符号链接:空,
eslint:[对象]
},
下一个:{data:[文件],下一个:null}
},
尾部:{
数据:文件{
stat:[Stats],
_内容:[缓冲区[Uint8Array]],
历史记录:[数组],
_cwd:C:\\公司机密资料',
_base:'C:\\company secret stuff\\Scripts',
_是的,
_符号链接:空,
eslint:[对象]
},
下一个:空
},
长度:2
},
长度:2,
管道:[],
流:null,
结束:错,
提交:错误,
阅读:没错,
同步:假,
对,,
错误:错误,
可读性听力:错误,
resumeScheduled:false,
对,,
是的,
自动销毁:对,
是的,
错误:[循环*1],
关闭:是的,
答案:错,
defaultEncoding:'utf8',
DrainWriters:空,
多目标:错误,
阅读更多:错误,
解码器:空,
编码:空,
[符号(kPaused)]:空
},
_事件:[对象:null原型]{prefish:[函数:prefish]},
_事件提示:1,
_maxListeners:未定义,
_writableState:writableState{
objectMode:true,
高水位:16,
最终结论:错误,
李安:错,
结尾:对,
结束:对,
完成:假,
是的,
是的,
defaultEncoding:'utf8',
长度:0,
写作:错,
软木塞:0,
同步:假,
缓冲处理:false,
onwrite:[函数:绑定onwrite],
writeb:null,
writelen:0,
AfterWritecKinfo:null,
缓冲:[],
缓冲索引:0,
是的,
是的,
待定CB:1,
是的,
对,,
是的,
自动销毁:对,
错误:[循环*1],
关闭:正确
},
AllowAlfOpen:是的,
_转换:[函数(匿名)],
_刷新:[函数(匿名)],
[符号(kCapture)]:假,
[符号(kTransformState)]:{
后转换:[函数:绑定后转换],
是的,
转变:错,
writeb:null,
writechunk:null,
writeencoding:'utf8'
}
},
域名:假
}
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
}