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

More complete throw/yield detection #682

Closed
brettz9 opened this issue Jan 28, 2021 · 1 comment
Closed

More complete throw/yield detection #682

brettz9 opened this issue Jan 28, 2021 · 1 comment

Comments

@brettz9
Copy link
Collaborator

brettz9 commented Jan 28, 2021

Expected behavior

For our utility hasThrowValue (used by require-throws) and hasYieldValue (used by require-yields and require-yields-check), I believe we may need to support some of the following AST branches (even if not of interest to hasReturns on which these functions were based).

  case 'SequenceExpression': // Comma
  case 'ArrayExpression': case 'AssignmentExpression': case 'AssignmentPattern':
  case 'AwaitExpression': case 'BinaryExpression': case 'ConditionalExpression':
  case 'LogicalExpression': case 'MemberExpression': case 'OptionalMemberExpression':
  case 'VariableDeclaration':
  case 'OptionalCallExpression':
  case 'TaggedTemplateExpression':
  case 'TemplateElement': case 'TemplateLiteral': case 'UnaryExpression':
  case 'SpreadElement':
  case 'ArrayPattern': case 'ObjectPattern':
  case 'ObjectExpression':
  case 'Property':
  case 'ClassProperty':
  case 'ClassDeclaration': case 'ClassExpression': case 'MethodDefinition':
  case 'Super':
  case 'ExportDefaultDeclaration': case 'ExportNamedDeclaration':
  case 'LabeledStatement':
  case 'Import':
  case 'ImportExpression':
  case 'Decorator':
  case 'YieldExpression':

And if #683 is accepted, these checks will be needed for resolve as well (in its hasValueOrExecutorHasNonEmptyResolveValue).

Actual behavior

Treats those expressions (and anything within them, including any throw/yield) as not throwing/not yielding.

So, require-throws and require-yields may falsely fail to report and require-yields-check can report when it should not.

ESLint Config

{
  'jsdoc/require-throws': 'error',
  'jsdoc/require-yields': 'error',
  'jsdoc/require-yields-check': 'error',
}

ESLint sample

/**
 *
 */
function * quux () {
  false || (() => {
    throw new Error();
  })();

  var a = [yield];
}

Environment

  • Node version: 12.16.2
  • ESLint version 7.18.0
  • eslint-plugin-jsdoc version: 31.4.0
@brettz9 brettz9 added the bug label Jan 28, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jan 31, 2021
@gajus
Copy link
Owner

gajus commented Jan 31, 2021

🎉 This issue has been resolved in version 31.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants