Rule proposal: no catch throw
fregante opened this issue · 2 comments
fregante commented
Description
https://x.com/devagrawal09/status/1842073035517403534
Not sure how common this is, but. Maybe it’s an easy rule?
Fail
try {
something()
} catch (error) {
throw error
}
something.catch(error => {throw error})
Pass
something()
try {
something()
} catch (error) {
errors.add(error)
throw error
}
Proposed rule name
no-useless-catch-throw
Additional Info
I’d rather see this first though:
dimaMachina commented
Eslint already has built-in rule :) (not sure if it works with 2nd failed example) https://eslint.org/docs/latest/rules/no-useless-catch
fregante commented
Perfect!
not sure if it works with 2nd failed example
Doesn't look like it, but we have https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/prefer-await-to-then.md and in the future: