-
Notifications
You must be signed in to change notification settings - Fork 49
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 prefer-t-throws
rule
#345
base: main
Are you sure you want to change the base?
Conversation
AVA now has |
So should the rule be |
The name should be the what it is, but you need to also support the async method. |
const createAvaRule = require('../create-ava-rule'); | ||
const util = require('../util'); | ||
|
||
// This function checks if there is an AwaitExpression, which is not inside another function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could find an AwaitExpression
, then iterate upwards through its parent scopes until you encounter a function, and then check the function.
https://eslint.org/docs/developer-guide/scope-manager-interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the ReturnStatement
? I doubt there's anything simpler than that in the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a realistic example of when someone would actually use return
in a try/catch when testing an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't have one. It's pretty hard to find a realistic example but I have a feeling that there might be some code written that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling that there might be some code written that way.
Rule logic should be based on test fixtures, not feelings. My recommendation to simplify the logic here stands.
6755db3
to
1561b35
Compare
Fixes: #156
IssueHunt Summary
Referenced issues
This pull request has been submitted to:
prefer-t-throws