Code Monkey home page Code Monkey logo

Comments (7)

xjamundx avatar xjamundx commented on May 25, 2024 1

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.

barkthins avatar barkthins commented on May 25, 2024

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.

xjamundx avatar xjamundx commented on May 25, 2024

@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.

barkthins avatar barkthins commented on May 25, 2024

@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.

xjamundx avatar xjamundx commented on May 25, 2024

K I'll keep this open until I get some time to figure it out!

from eslint-plugin-promise.

scottnonnenberg avatar scottnonnenberg commented on May 25, 2024

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.

xjamundx avatar xjamundx commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.