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

Add rule require-throws #574

Merged
merged 7 commits into from Jun 17, 2020
Merged

Add rule require-throws #574

merged 7 commits into from Jun 17, 2020

Conversation

0xCLARITY
Copy link
Contributor

@0xCLARITY 0xCLARITY commented Jun 10, 2020

This adds a new rule require-throws, that requires a @throws statement in the JSDoc if the function body contains the throw keyword.

I based this off of require-returns, as suggested in #566


const tagName = utils.getPreferredTagName({tagName: 'throws'});
if (!tagName) {
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to cover this case in a test?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be enough to add a (passing) example which doesn't have @throws at all (or where it has @throws but settings.jsdoc.tagNamePreference is set to map throws to something else like throw and if @throw wasn't present).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only line that I can't figure out how to cover. I feel like it should be covered by this test, but it seems like I'm not understanding how utils.getPreferredTagName() is working?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I've added the test (it was setting throws to false on tagNamePreference settings, i.e., if someone had indicated they wished to block the throws tag yet were still using this rule. :)

I think it looked good, but need a little more time to give it another look over before merging.

@0xCLARITY 0xCLARITY marked this pull request as ready for review June 10, 2020 16:42
@0xCLARITY 0xCLARITY marked this pull request as draft June 10, 2020 16:42
@0xCLARITY
Copy link
Contributor Author

@brettz9 , does this look like I'm on the right track?

@brettz9
Copy link
Collaborator

brettz9 commented Jun 11, 2020

Looks very good from a quick look!

0xCLARITY and others added 3 commits June 12, 2020 14:44
* master:
  fix(check-param-names, require-param): handle ts constructor as arg; fixes #576
  fix(`check-param-names`): destructured parameters inclusion check (params containing other params as substrings); closes #575
  Revert "Fix bug with destructured parameters in check-param-names"
  Fix bug with destructured parameters in check-param-names
@0xCLARITY 0xCLARITY marked this pull request as ready for review June 15, 2020 13:09
@0xCLARITY
Copy link
Contributor Author

@brettz9 , thanks for adding the missing test! I'll know for next time to add a case where the tag is given in the JSDoc but should not be.

@0xCLARITY 0xCLARITY requested a review from brettz9 June 15, 2020 13:09
@0xCLARITY 0xCLARITY changed the title WIP: Add rule require-throws Add rule require-throws Jun 15, 2020
@0xCLARITY 0xCLARITY marked this pull request as draft June 15, 2020 13:10
@0xCLARITY 0xCLARITY marked this pull request as ready for review June 15, 2020 13:20
@brettz9 brettz9 merged commit 3d3c38b into gajus:master Jun 17, 2020
@brettz9
Copy link
Collaborator

brettz9 commented Jun 17, 2020

Great work, thanks!

@gajus
Copy link
Owner

gajus commented Jun 17, 2020

🎉 This PR is included in version 27.1.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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants