question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: option for consistent-return to not treat return in generator functions as error

See original GitHub issue

What rule do you want to change?

consistent-return

Does this change cause the rule to produce more or fewer warnings?

fewer

How will the change be implemented? (New option, new default behavior, etc.)?

New option

Please provide some example code that this change will affect:

function* exampleGenerator(option) {
    if (option === false) {
        return [];
    }

    yield* [1, 2, 3];
}

What does the rule currently do for this code?

Currently, this will produce an error, as there isn’t an error for all branches of code. However, returning in a generator is a valid way to exhaust a generator early.

What will the rule do after it’s changed?

With an option to the rule (something like "ignoreGenerators": true), the rule could ignore generator functions. I think an argument could be made that for generator functions, yield statements could be treated the same as return statements, at least for the purposes of this rule, but that might be a larger change.

Are you willing to submit a pull request to implement this change?

Yes.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Feb 10, 2019

Personally, I think it would be better to update the default behavior here rather than adding a new option.

0reactions
nzakascommented, Jun 19, 2020

Agreed, I don’t think we need to make a change here. Thanks everyone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

consistent-return - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Proposal - async/generator functions in ClojureScript
So any yield or await caught inside one of these IIFEs would throw an error. If no value is returned from the IIFE,...
Read more >
22. Generators - Exploring JS
I have omitted method return() of interface Iterable , because it is not relevant in this section. A generator function produces a sequence...
Read more >
Python Generators - Dataquest
Python generators are a powerful, but misunderstood tool. Use this tutorial to begin understanding, and using, generators.
Read more >
@sailshq/eslint | Yarn - Package Manager
In other words, there will never be any new methods or options added to eslint ... 3ff5d11 Fix: no-invalid-regexp not understand variable for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found