Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule to prevent no-op promise handlers #12

Open
ForbesLindesay opened this issue Apr 12, 2016 · 3 comments
Open

Rule to prevent no-op promise handlers #12

ForbesLindesay opened this issue Apr 12, 2016 · 3 comments

Comments

@ForbesLindesay
Copy link
Contributor

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.

@xjamundx
Copy link
Contributor

xjamundx commented Jun 3, 2016

Agreed this is a good idea

@xjamundx
Copy link
Contributor

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.

@macklinu
Copy link
Contributor

Taking a look at implementing this rule this week.

@macklinu macklinu self-assigned this Feb 14, 2018
macklinu added a commit that referenced this issue Feb 14, 2018
macklinu added a commit that referenced this issue Feb 14, 2018
macklinu added a commit that referenced this issue Feb 23, 2018
macklinu added a commit that referenced this issue Feb 25, 2018
macklinu added a commit that referenced this issue Mar 8, 2018
macklinu added a commit that referenced this issue May 24, 2018
macklinu added a commit that referenced this issue May 24, 2018
@ota-meshi ota-meshi removed the has pr label Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants