Skip to content
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

Allow yieldAsReturn option in conjunction with new settings.jsdoc.mode #355

Closed
wants to merge 1 commit into from

Conversation

brettz9
Copy link
Collaborator

@brettz9 brettz9 commented Jul 23, 2019

feat(require-returns-check): with settings.jsdoc.mode (typescript or gcc), allow yieldAsReturn option as "always" or "argument" to treat yield as return (fixes #271)

The mode setting--as discussed in another issues--would allow precise tweaking of behavior across other rules as well (e.g., for check-tag-names to disallow @template by default in regular jsdoc mode, but allow it with gcc). But this PR only ensures that regular jsdoc mode cannot treat yield as a return since regular jsdoc has the @yields tag which may be used for that purpose.

@brettz9 brettz9 requested a review from golopot July 23, 2019 22:09
@brettz9 brettz9 mentioned this pull request Jul 23, 2019
13 tasks
@brettz9 brettz9 force-pushed the require-returns-check-yield branch from 861bc7c to 0f0295d Compare July 24, 2019 03:24
@golopot
Copy link
Collaborator

golopot commented Jul 24, 2019

I think a better approach is to skip require-returns-check rule for all generator functions. A generator function always returns an iterator, regardless of the presence of yield statement. This approach is analogous to how we treat async functions in the rule.

@brettz9
Copy link
Collaborator Author

brettz9 commented Jul 24, 2019

For jsdoc mode, I was in agreement--and I would hope TypeScript/GCC will come to support @yields to differentiate. My thinking was to allow for TypeScript/GCC just for the time-being, overloading @returns.

However, in looking at microsoft/TypeScript#23857 , I see that they already have a syntax for overloading @returns, indicating (similar to how Promises can be documented) the type yielded by the iterator, IterableIterator<Something> in the issue example. The issue mentions eslint valid-jsdoc as complaining, but that, as we know, is deprecated, and we can of course, get it to work ourselves.

So rather than skipping checking for generators, I think we should make sure that unless it is IterableIterator<void> or such (in which case just a yield might be expected), we should require yield with a value. It shouldn't be hard to adapt this PR to do this, and it'd avoid the need for the option.

@golopot
Copy link
Collaborator

golopot commented Jul 24, 2019

That feature should be addressed in #354 in a separate rule.

… or `gcc`), allow `yieldAsReturn` option as "always" or "argument" to treat `yield` as `return` (fixes gajus#271)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

require-returns-check doesn't work with generator functions
2 participants