Proposal: option for consistent-return to not treat return in generator functions as error
See original GitHub issueWhat 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:
- Created 5 years ago
- Reactions:4
- Comments:8 (8 by maintainers)
Top GitHub Comments
Personally, I think it would be better to update the default behavior here rather than adding a new option.
Agreed, I don’t think we need to make a change here. Thanks everyone.