Comments (7)
right because I personally prefer the no-else-return
rule, so in my case I'd still do the return 200
at the root level of the function.
Yeah totally valid bug though, solution is tricky to enforce properly.
We could check that there's any return
inside of a then
function. For example:
.then(function(p) {
if (p < 10) {
return p * 1000;
}
})
But then it obviously misses cases like this where the root of the function isn't covered, but to some extent that is covered by consistent-return
.
What do you think? Would you be able to try to make the code change?
from eslint-plugin-promise.
funny thing is worked on medical devices and prefer else-return
. Please cite why no-else-return
is a rule...
If you don't have enough of the parse tree to figure out all the cases possible and make sure there's a return for each case, then you probably can't solve the problem. I don't know enough about how eslint works to know whether that's possible.
from eslint-plugin-promise.
@barkthins I use no-else-return
in javascript, because of the endless callback functions. This saves one level of nesting on the else
path
As far as creating custom ESLint rules, we do have a full tree, it's just the tools for traversing it are pretty weak, so checking every path is pretty difficult. Code path analysis landed which is supposed to make this easier and may be worth checking out.
I'd love your help adding this ability to the rule, let me know if you can do it!
from eslint-plugin-promise.
@xjamundx I use promises. What's this issue with callback nesting you speak of? ;-P
My plate is stacked high and deep, being at a startup. I'm busy enough answering Ethereum questions, I'm afraid another community will give me overload...
from eslint-plugin-promise.
K I'll keep this open until I get some time to figure it out!
from eslint-plugin-promise.
Not exactly the same, but very similar - I get an 'each then() should return a value' error for this:
.then(([response, text]) => {
try {
return [response, parseWithDates(text)];
}
catch (e) {
return [response];
}
})
As well as for this, from my tests:
return fetch.default()
.then(() => {
throw new Error('expected error to be thrown');
})
.catch(error => {
expect(error).to.have.property('message', 'Something went wrong!');
});
from eslint-plugin-promise.
ahh thanks for the note @scottnonnenberg I'll try to look at this..in the meantime you may be abe to do something like this:
var dates
try { dates = parseWithDates(text) }
catch (e) { data = undefined }
return [response, dates]
from eslint-plugin-promise.
Related Issues (20)
- > @xjamundx what can we do to help to get this merged? HOT 1
- > @xjamundx what can we do to help to get this merged? HOT 1
- > > @xjamundx what can we do to help to get this merged? HOT 1
- No tag for v5.2.0 HOT 5
- prefer-await-to-then doesn't enforce .then/.catch/.finally HOT 2
- Invitation to move to official `eslint-community` org
- Consider automatic releases HOT 1
- Add support for Promise.allSettled() and Promise.any() HOT 1
- `no-multiple-resolved` wrongly reports `reject` in try/catch block HOT 6
- .github/workflows/CI.yml
- `promise/prefer-await-to-then` ignore constructor scope HOT 1
- Rule to require that Promise executor function calls resolve
- `no-multiple-resolved` wrongly reports `reject` in try/catch block
- False positive of `isInsideCallback` for functions with first arg named `err`/`error`
- does it support typescript?
- New Rule: Prefer `Promise.resolve(foo)` to `new Promise((resolve) => resolve(foo))`
- Support ESLint 9 and Flat config HOT 13
- apromise/catch-or-return will cause many empty callback of match
- `promise/always-return` should not be reported when process exits HOT 1
- `always-return`: enable `ignoreLastCallback` by default
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-promise.