eslint-community/eslint-plugin-promise

Rule to prevent no-op promise handlers

開放

#12 建立於 2016年4月12日

 (3 則留言) (0 個反應) (1 位負責人)JavaScript (103 個分叉)auto 404
enhancementhelp wanted

倉庫指標

星標
 (998 顆星)
PR 合併指標
 (平均合併 1天 2小時) (30 天內合併 12 個 PR)

描述

See: eslint/eslint#5761

Rule to throw when the identify function is used as the success handler of a Promise or the "throw function" is used as the failure handler of a Promise.

// The identity function is the default success handler for a promise, it can be ommitted
something.then(function (value) {
  return value;
});

// and

// propagating the error is the default error handler fro a promise, it can be ommitted

something.then(null, function (err) {
  throw err;
});

// or

something.catch(function (err) {
  throw err;
});

It helps users to understand how promise values propagate.

Usually when people write .catch(err => { throw err; }) they intend to throw the error into the next tick to make sure it's reported, not to add a no-op to the end of their promise chain.

貢獻者指南