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.

贡献者指南