8000 feat(eslint-plugin): [only-throw-error] add option `allowRethrowing` by kirkwaiblinger · Pull Request #11075 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

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

Conversation

kirkwaiblinger
Copy link
Member
@kirkwaiblinger kirkwaiblinger commented Apr 15, 2025

PR Checklist

Overview

There's some doubt over whether a captured catch variable should be considered a rethrow... For example, is this a rethrow?

try {
   // ...
} catch (e) {
   setTimeout(() => { throw e; }, 0);
}

For now, I've implemented it that yes, that's a rethrow, but we could also demand that rethrows must occur within the same function scope as they're caught. This would "false positive" on synchronously executed functions, though, like

try {
   // ...
} catch (e) {
   [1, 2, 3].foreach(x => { if (x % 2 === 0) throw e; });
}

IMO, calling that a rethrow is really a stretch, so I'm gently in favor of banning captured variable rethrows, but I could be convinced either way.


Also included some minor refactoring to use common utilities for parsing .then()/.catch() calls.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @kirkwaiblinger!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link
netlify bot commented Apr 15, 2025

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 786c589
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6818d93a1f8fb800086ac4bd
😎 Deploy Preview https://deploy-preview-11075--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 98 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
nx-cloud bot commented Apr 15, 2025

View your CI Pipeline Execution ↗ for commit 786c589.

Command Status Duration Result
nx typecheck ast-spec ✅ Succeeded 3s View ↗
nx run-many --target=build --exclude website --... ✅ Succeeded 50s View ↗
nx run-many --target=clean ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2025-05-05 16:09:24 UTC

Copy link
codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.93%. Comparing base (cc2d6ec) to head (786c589).
Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11075      +/-   ##
==========================================
+ Coverage   90.83%   90.93%   +0.09%     
==========================================
  Files         497      499       +2     
  Lines       50279    50789     +510     
  Branche
8000
s     8297     8368      +71     
==========================================
+ Hits        45672    46183     +511     
+ Misses       4592     4591       -1     
  Partials       15       15              
Flag Coverage Δ
unittest 90.93% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...es/eslint-plugin/src/rules/no-floating-promises.ts 98.37% <100.00%> (-0.06%) ⬇️
...ckages/eslint-plugin/src/rules/only-throw-error.ts 100.00% <100.00%> (ø)
packages/eslint-plugin/src/util/promiseUtils.ts 100.00% <100.00%> (ø)

... and 12 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kirkwaiblinger kirkwaiblinger marked this pull request as ready for review May 1, 2025 16:56
JoshuaKGoldberg
JoshuaKGoldberg previously approved these changes May 2, 2025
Copy link
Member
@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Really nifty stuff! I like the extraction+reuse for Promise detection. Left a few comments, nothing close to blocking IMO. 🔥

*
* @default false
*/
allowRethrowing?: boolean;
Copy link
Member

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 8000 in this PR?

If you'd rather them all tackled together as a followup, I wouldn't block.

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label May 2, 2025
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label May 5, 2025
@@ -6,7 +6,8 @@
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker",
"tlent.jest-snapshot-language-support",
"mrmlnc.vscode-json5"
"mrmlnc.vscode-json5",
"unifiedjs.vscode-mdx"
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated?

Copy link
Member

Choose a reason for hiding this comment

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

I removed this just to be able to merge before the release today - but I wouldn't be against the extension in general

@JoshuaKGoldberg JoshuaKGoldberg merged commit 29ea555 into typescript-eslint:main May 5, 2025
53 checks passed
@kirkwaiblinger kirkwaiblinger deleted the only-throw-error-rethrow branch May 5, 2025 15:54
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 10, 2025
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.31.0 | 8.32.0 |
| npm        | @typescript-eslint/parser        | 8.31.0 | 8.32.0 |


## [v8.32.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8320-2025-05-05)

##### 🚀 Features

-   **eslint-plugin:** \[only-throw-error] add option `allowRethrowing` ([#11075](typescript-eslint/typescript-eslint#11075))
-   **eslint-plugin:** \[no-unnecessary-type-conversion] add rule ([#10182](typescript-eslint/typescript-eslint#10182))

##### 🩹 Fixes

-   **eslint-plugin:** \[prefer-nullish-coalescing] fix parenthesization bug in suggestion ([#11098](typescript-eslint/typescript-eslint#11098))
-   **eslint-plugin:** \[unified-signatures] exempt `this` from optional parameter overload check ([#11005](typescript-eslint/typescript-eslint#11005))
-   **eslint-plugin:** \[no-unnecessary-type-parameters] should parenthesize type in suggestion fixer if necessary ([#10907](typescript-eslint/typescript-eslint#10907))

##### ❤️ Thank You

-   Andy Edwards
-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)
-   mdm317
-   Sasha Kondrashov
-   Yukihiro Hasegawa [@y-hsgw](https://github.com/y-hsgw)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.


## [v8.31.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8311-2025-04-28)

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-condition] downgrade fix to suggestion ([#11081](typescript-eslint/typescript-eslint#11081))

##### ❤️ Thank You

-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 10, 2025
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.31.0 | 8.32.0 |
| npm        | @typescript-eslint/parser        | 8.31.0 | 8.32.0 |


## [v8.32.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8320-2025-05-05)

##### 🚀 Features

-   **eslint-plugin:** \[only-throw-error] add option `allowRethrowing` ([#11075](typescript-eslint/typescript-eslint#11075))
-   **eslint-plugin:** \[no-unnecessary-type-conversion] add rule ([#10182](typescript-eslint/typescript-eslint#10182))

##### 🩹 Fixes

-   **eslint-plugin:** \[prefer-nullish-coalescing] fix parenthesization bug in suggestion ([#11098](typescript-eslint/typescript-eslint#11098))
-   **eslint-plugin:** \[unified-signatures] exempt `this` from optional parameter overload check ([#11005](typescript-eslint/typescript-eslint#11005))
-   **eslint-plugin:** \[no-unnecessary-type-parameters] should parenthesize type in suggestion fixer if necessary ([#10907](typescript-eslint/typescript-eslint#10907))

##### ❤️ Thank You

-   Andy Edwards
-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)
-   mdm317
-   Sasha Kondrashov
-   Yukihiro Hasegawa [@y-hsgw](https://github.com/y-hsgw)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.


## [v8.31.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8311-2025-04-28)

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-condition] downgrade fi
67E6
x to suggestion ([#11081](typescript-eslint/typescript-eslint#11081))

##### ❤️ Thank You

-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 11, 2025
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.31.0 | 8.32.0 |
| npm        | @typescript-eslint/parser        | 8.31.0 | 8.32.0 |


## [v8.32.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8320-2025-05-05)

##### 🚀 Features

-   **eslint-plugin:** \[only-throw-error] add option `allowRethrowing` ([#11075](typescript-eslint/typescript-eslint#11075))
-   **eslint-plugin:** \[no-unnecessary-type-conversion] add rule ([#10182](typescript-eslint/typescript-eslint#10182))

##### 🩹 Fixes

-   **eslint-plugin:** \[prefer-nullish-coalescing] fix parenthesization bug in suggestion ([#11098](typescript-eslint/typescript-eslint#11098))
-   **eslint-plugin:** \[unified-signatures] exempt `this` from optional parameter overload check ([#11005](typescript-eslint/typescript-eslint#11005))
-   **eslint-plugin:** \[no-unnecessary-type-parameters] should parenthesize type in suggestion fixer if necessary ([#10907](typescript-eslint/typescript-eslint#10907))

##### ❤️ Thank You

-   Andy Edwards
-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)
-   mdm317
-   Sasha Kondrashov
-   Yukihiro Hasegawa [@y-hsgw](https://github.com/y-hsgw)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.


## [v8.31.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8311-2025-04-28)

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-condition] downgrade fix to suggestion ([#11081](typescript-eslint/typescript-eslint#11081))

##### ❤️ Thank You

-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: [only-throw-error] allow re-throwing a caught error
2 participants
0