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] Add an option to require a returns-tag if TS type annotation is other than void/Promise<void> #517

Closed
manuth opened this issue Apr 15, 2020 · 4 comments · Fixed by #976

Comments

@manuth
Copy link
Contributor

manuth commented Apr 15, 2020

In typescript you have the option to specify the return-type of a function:

// Function
function test(): string { }
// Arrow-Function
let test = (): string => { };
// FunctionType
let test: () => string;

// Abstract method
class Test {
  abstract Test(): string;
}

Do you guys think its smart to add an option to also require a @returns-parameter if a return-type other than none, void or Promise<void> is specified?
Or do you think this would go too far?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@brettz9
Copy link
Collaborator

brettz9 commented Apr 16, 2020

If you mean to check the actual return value to see if @returns is needed, there is already require-returns. But I guess you mean that if using TypeScript return types, @returns should be required? Some users may actually want to disable the rule in such cases as it might be seen as partially redundant, though I can see some would want one if one is requiring a description.

I'd be ok with such a feature myself or reviewing a PR, though as I'm not working with TS, that would not be on my priority list.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 1, 2023
… with non-void return-type type annotations; closes gajus#517
brettz9 added a commit that referenced this issue Feb 1, 2023
… with non-void return-type type annotations; closes #517
@brettz9
Copy link
Collaborator

brettz9 commented Feb 1, 2023

This can be achieved now with the jsdoc/no-restricted-syntax rule. See #976 (specifically https://github.com/gajus/eslint-plugin-jsdoc/pull/976/files#diff-545a867764ce23fa04a08e7f0207aacd009b8343965ede162d8f09d9b718a844 ) for the options you can supply to detect and report on type annotations with non-void return types missing the @returns or @returns with a description.

@brettz9
Copy link
Collaborator

brettz9 commented Feb 1, 2023

For example:

/**
 * @returns
 */
let test: () => string;

will err with the following options due to not having a description line within the @returns:

'jsdoc/no-restricted-syntax': [
  'error',
  {
    contexts: [
      {
        comment: 'JsdocBlock:not(*:has(JsdocTag[tag=/returns/]:has(JsdocDescriptionLine)))',
        context: 'VariableDeclaration:has(*[typeAnnotation.typeAnnotation.type=/TSFunctionType/][typeAnnotation.typeAnnotation.returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/])',
        message: 'FunctionType\'s with non-void return types must have a @returns tag with a description',
      },
    ],
  },
],

@github-actions
Copy link

github-actions bot commented Feb 3, 2023

🎉 This issue has been resolved in version 39.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants