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

require-returns-check doesn't work with generator functions #271

Closed
leomeloxp opened this issue Jun 3, 2019 · 4 comments
Closed

require-returns-check doesn't work with generator functions #271

leomeloxp opened this issue Jun 3, 2019 · 4 comments

Comments

@leomeloxp
Copy link

When trying to write a generator function (*myfunction) require-returns-check complains that no return statement is found even though the function contains the yield keyword (which essentially works as a return.

Example code (using Typescript):

    /**
     * Generator for prizes:
     * @returns {IterableIterator<number>}
     * @memberof GameController
     */
    public *prizes(): IterableIterator<number> {
        for (const prizeValue of this.prizes) {
            yield prizeValue;
        }
    }

I searched through existing issues and found that there were some issues with the checker and implicit returns before. I believe this would be a similar kind of issue, if someone gives me some tips I could try and PR a fix for it.

@brettz9
Copy link
Collaborator

brettz9 commented Jun 3, 2019

It has been enhanced considerably, but that would be a nice addition. However, I think we'd want to distinguish (maybe toggled with an option) cases where yield's were of the form let receivedValue = yield; (without a returned value) and whether these would be considered as returning a value or not.

@brettz9
Copy link
Collaborator

brettz9 commented Jun 3, 2019

I've found https://astexplorer.net/ quite helpful in getting around the AST...

@brettz9
Copy link
Collaborator

brettz9 commented Jul 23, 2019

Btw, while @yields is not currently supported in TypeScript, I think for jsdoc users, it would make more sense to check that tag instead.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 23, 2019
… or `gcc`), allow `yieldAsReturn` option as "always" or "argument" to treat `yield` as `return` (fixes gajus#271)
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 24, 2019
… or `gcc`), allow `yieldAsReturn` option as "always" or "argument" to treat `yield` as `return` (fixes gajus#271)
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 25, 2019
… or `gcc`), allow `yieldAsReturn` option as "always" or "argument" to treat `yield` as `return` (fixes gajus#271)
@brettz9
Copy link
Collaborator

brettz9 commented Jul 29, 2019

Closing in favor of #354 . For TypeScript at least, #354 should also allow the IterableIterator @returns as as well as @yields

@brettz9 brettz9 closed this as completed Jul 29, 2019
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Oct 30, 2019
… or `gcc`), allow `yieldAsReturn` option as "always" or "argument" to treat `yield` as `return` (fixes gajus#271)
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Oct 30, 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 gajus#271)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants