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
Rationale behind avoid-new? #111
Comments
These are good questions and things we should either reconsider or document more clearly why the |
That was clever, 🤣
Here's an example of a few versions of the same thing: new Promise((resolve, reject) => {
resolve("4")
})
// vs.
Promise.resolve("4") new Promise((resolve, reject) => {
doSomethingLong("please", function(err, data) {
if (err) return reject(err)
resolve(data)
})
// vs.
let longThing = require('util').promisify(doSomethingLong)
longThing("please")
Now I know |
I think you both make a reasonable case. I'm also not tied to it being in the recommended ruleset. A couple PRs are welcome:
|
@xjamundx your examples are good for Node, what about a browser-targeted library? |
This was my use case as well, I've mostly bumped into this rule on client-side code which is why it was so hard for me to make sense of it. |
Good point about browser-based code, where the #119 is open to remove this rule from the recommended ruleset. I aim to take care of some outstanding PRs and ship a minor release in the coming days that will include this. 👍 |
It's about creating clean and readable code. A promisified method is much more readable than wrapping something in However, I agree the rule is not suitable for the |
Here's my specific client-side function where I'm wanting to avoid this warning:
Example usage:
Without using a 3rd party library, can you think of an elegant way of not using Does the eslint-plugin-promise plugin provide comment directives that would allow me to override the warning for only this function? To me, the usefulness of this rule is to avoid those circumstance when you create a new promise when you didn't need to. I like removing those, but here I needed to (I think), so I'd like to override having to see that warning each build. Please advise. |
I'm not sure I understand why this rule is in the
recommended
ruleset, it doesn't say whynew Promise
should be avoided in the docs (in case of misuse?). And I find the fact it recommends a third party package instead a bit (p)iffy.I see the rule has been added in 2016, is it still relevant today now that promises are more widely supported?
The text was updated successfully, but these errors were encountered: