-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [only-throw-error] add option allowRethrowing
#11075
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
Merged
JoshuaKGoldberg
merged 15 commits into
typescript-eslint:main
from
kirkwaiblinger:only-throw-error-rethrow
May 5, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2903ff5
wip
kirkwaiblinger 26a6b9e
Merge branch 'main' into only-throw-error-rethrow
kirkwaiblinger 7d4332c
progress
kirkwaiblinger c3cfb66
comment
kirkwaiblinger 0b13b1d
snapshots
kirkwaiblinger fc852e6
Merge branch 'main' into only-throw-error-rethrow
kirkwaiblinger 29f2160
cov
kirkwaiblinger a472855
cov2
kirkwaiblinger 4febd74
docs
kirkwaiblinger 22b249a
revert unrelated change
kirkwaiblinger e2da1c9
more comments
kirkwaiblinger dd71c12
fixup
kirkwaiblinger e583c08
Update packages/eslint-plugin/docs/rules/only-throw-error.mdx
kirkwaiblinger 3237b22
simplify type assertion
kirkwaiblinger 786c589
fix lint and an unrelated change
JoshuaKGoldberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import type { TSESTree } from '@typescript-eslint/utils'; | ||
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint'; | ||
|
||
import { AST_NODE_TYPES } from '@typescript-eslint/utils'; | ||
|
||
import { getStaticMemberAccessValue } from './misc'; | ||
|
||
/** | ||
* Parses a syntactically possible `Promise.then()` call. Does not check the | ||
* type of the callee. | ||
*/ | ||
export function parseThenCall( | ||
node: TSESTree.CallExpression, | ||
context: RuleContext<string, unknown[]>, | ||
): | ||
| { | ||
onFulfilled?: TSESTree.Expression | undefined; | ||
onRejected?: TSESTree.Expression | undefined; | ||
object: TSESTree.Expression; | ||
} | ||
| undefined { | ||
if (node.callee.type === AST_NODE_TYPES.MemberExpression) { | ||
const methodName = getStaticMemberAccessValue(node.callee, context); | ||
if (methodName === 'then') { | ||
if (node.arguments.length >= 1) { | ||
if (node.arguments[0].type === AST_NODE_TYPES.SpreadElement) { | ||
return { | ||
object: node.callee.object, | ||
}; | ||
} | ||
|
||
if (node.arguments.length >= 2) { | ||
if (node.arguments[1].type === AST_NODE_TYPES.SpreadElement) { | ||
return { | ||
object: node.callee.object, | ||
onFulfilled: node.arguments[0], | ||
}; | ||
} | ||
|
||
return { | ||
object: node.callee.object, | ||
onFulfilled: node.arguments[0], | ||
onRejected: node.arguments[1], | ||
}; | ||
} | ||
return { | ||
object: node.callee.object, | ||
onFulfilled: node.arguments[0], | ||
}; | ||
} | ||
return { | ||
object: node.callee.object, | ||
}; | ||
} | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
/** | ||
* Parses a syntactically possible `Promise.catch()` call. Does not check the | ||
* type of the callee. | ||
*/ | ||
export function parseCatchCall( | ||
node: TSESTree.CallExpression, | ||
context: RuleContext<string, unknown[]>, | ||
): | ||
| { | ||
onRejected?: TSESTree.Expression | undefined; | ||
object: TSESTree.Expression; | ||
} | ||
| undefined { | ||
if (node.callee.type === AST_NODE_TYPES.MemberExpression) { | ||
const methodName = getStaticMemberAccessValue(node.callee, context); | ||
if (methodName === 'catch') { | ||
if (node.arguments.length >= 1) { | ||
if (node.arguments[0].type === AST_NODE_TYPES.SpreadElement) { | ||
return { | ||
object: node.callee.object, | ||
}; | ||
} | ||
|
||
return { | ||
object: node.callee.object, | ||
onRejected: node.arguments[0], | ||
}; | ||
} | ||
return { | ||
object: node.callee.object, | ||
}; | ||
} | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
/** | ||
* Parses a syntactically possible `Promise.finally()` call. Does not check the | ||
* type of the callee. | ||
*/ | ||
export function parseFinallyCall( | ||
node: TSESTree.CallExpression, | ||
context: RuleContext<string, unknown[]>, | ||
): | ||
| { | ||
object: TSESTree.Expression; | ||
onFinally?: TSESTree.Expression | undefined; | ||
} | ||
| undefined { | ||
if (node.callee.type === AST_NODE_TYPES.MemberExpression) { | ||
const methodName = getStaticMemberAccessValue(node.callee, context); | ||
if (methodName === 'finally') { | ||
if (node.arguments.length >= 1) { | ||
if (node.arguments[0].type === AST_NODE_TYPES.SpreadElement) { | ||
return { | ||
object: node.callee.object, | ||
}; | ||
} | ||
return { | ||
object: node.callee.object, | ||
onFinally: node.arguments[0], | ||
}; | ||
} | ||
return { | ||
object: node.callee.object, | ||
}; | ||
} | ||
} | ||
|
||
return undefined; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[Docs] The options mentions in this page don't explain why any of the options exist. I suppose that's existing/separate docs work for the other ones. But do you think it'd be reasonable to at least mention
allowRethrowing
in this PR?If you'd rather them all tackled together as a followup, I wouldn't block.