eslint-plugin-promise icon indicating copy to clipboard operation
eslint-plugin-promise copied to clipboard

Rule to prevent no-op promise handlers

Open ForbesLindesay opened this issue 9 years ago • 3 comments
trafficstars

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.

ForbesLindesay avatar Apr 12 '16 14:04 ForbesLindesay

Agreed this is a good idea

xjamundx avatar Jun 03 '16 19:06 xjamundx

Sorry to finally get back to these suggestions. I agree with this one. I imagine it's similar to how people sometimes do things like this:


doThing(function(err, data) {
    if (err) return callback(err)
    callback(null, data)
})

One decent reason for it is because it's a place to add some logging, but you know without the logs we should just remove it. I'm down. I'll see if I can work on this today/tomorow.

xjamundx avatar Oct 18 '16 16:10 xjamundx

Taking a look at implementing this rule this week.

macklinu avatar Feb 14 '18 04:02 macklinu