-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): add no-implicit-any-catch
rule
#2202
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
Conversation
Thanks for the PR, @phiresky! 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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
Also, since prettier does not support this syntax yet, the autoformatter currently strips the types from the docs etc on auto-format, which is pretty unhandy. |
Codecov Report
@@ Coverage Diff @@
## master #2202 +/- ##
==========================================
- Coverage 93.11% 93.10% -0.02%
==========================================
Files 283 284 +1
Lines 9061 9074 +13
Branches 2483 2487 +4
==========================================
+ Hits 8437 8448 +11
- Misses 301 302 +1
- Partials 323 324 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
haven't reviewed the code yet, just eyeballed it quickly.
two quick comments
thanks for your contribution!
Co-authored-by: Glen <glen.84@gmail.com>
Can we have an option on this that enforces I ideally want |
@tom-sherman, doesn't this PR already cover that? |
It does cover that, but I've defaulted it to false since I think you'd usually want to use the |
You're right, I missed that part - nice! |
…s to doc to work around prettier force formatting
I made a few updates to fix the CI, but for some reason github isn't picking up the changes. Feel free to take a look and merge master into your branch as well. |
You were able to push to a different users master branch? |
Wait, what? I did not know that was possible and I didn't add change any access permissions. Maybe this is a gihubt bug since github itself didn't even notice the repo change happened, and now the "update from master" button is broken? Regardless, I've merged upstream master into my branch again so now github has picked up the changes again. |
Never mind, I checked the |
@WORMSS As phiresky mentioned - GH has a setting on PRs which allows maintainers of the project you're PRing to to commit to the remote branch you want to merge. This permission is what enables the "update from master" button to work on the UI, but it also lets a maintainer do things like quick edit files in the UI. A keen observer also might note that this ofc means you can checkout the branch locally, make whatever changes, and push the changes. I usually avoid doing anything beyond updating from master because it:
I usually prefer to rely upon the contributor owning e2e and making the changes that I request, but sometimes I use it in the following cases:
Yeah, it looks like it was just a problem with github. Seems to be working now. |
okay as for the failing tests here - I think we should probably look to split out the 4.0.0 upgrade as a separate PR now. It looks like 4.0.0 has changed how Before, the TS parser just output I'll submit a PR this week to bump the version and fix all of the issues, and then we can rebase this PR to add the rule + support for type annotations on catch clause variables. |
# Conflicts: # packages/typescript-estree/src/convert.ts # packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts # packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap # packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
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.
This now LGTM - thanks for your contribution.
I'm going to wait until the 4.0.0-rc is released before merging.
New rules get automatically added to our all
config, so I don't want to force consumers of that to upgrade to a beta
TS version.
What about thrown Promises, should it be included in this rule too?
|
No - that |
no-implicit-any-catch
rule
In the next TS version, adding both
catch (e: unknown) {}
andcatch (e: any) {}
will be supported.This PR adds support for enforcing specifying a type for catch clauses. This is basically somethinng that should be caught by the
noImplicitAny
compiler flag, but probably won't be added to that because of backwards compatibility.See microsoft/TypeScript#36775 which was fixed here: microsoft/TypeScript#39015
This PR also adds support for the new syntax to typescript-estree.
The following pattern is considered a warning:
The following patterns are not warnings:
This PR will throw some "This snippet should be formatted correctly. Use the fixer to format the code" errors since this syntax is not yet supported in the formatter the lint is using.
To make this work, you need to set the TypeScript dependency to nightly (one containing this fix, wait until tomorrow :))