Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(eslint-plugin): addno-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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 18 commits intotypescript-eslint:masterfromphiresky:master
Aug 21, 2020

Conversation

phiresky
Copy link
Contributor

@phireskyphiresky commentedJun 11, 2020
edited
Loading

In the next TS version, adding bothcatch (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 thenoImplicitAny compiler flag, but probably won't be added to that because of backwards compatibility.

Seemicrosoft/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:

try{// ...}catch(e){// warning: Implicit any in catch clause// ...}

The following patterns are not warnings:

try{// ...}catch(e:unknown){// ...}
try{// ...}catch(e:any){// ...}

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 :))

tom-sherman, felixfbecker, albertms10, screendriver, lo1tuma, cyrilgandon, danielnixon, and langpavel reacted with thumbs up emojifelixfbecker, albertms10, and danielnixon reacted with heart emojiglen-84 reacted with eyes emoji
@typescript-eslint
Copy link
Contributor

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 onhttps://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitorsper day.

@phiresky
Copy link
ContributorAuthor

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
Copy link

codecovbot commentedJun 11, 2020
edited
Loading

Codecov Report

Merging#2202 intomaster willdecrease coverage by0.01%.
The diff coverage is84.61%.

@@            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
FlagCoverage Δ
#unittest93.10% <84.61%> (-0.02%)⬇️

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

Impacted FilesCoverage Δ
packages/eslint-plugin/src/configs/all.ts100.00% <ø> (ø)
...s/eslint-plugin/src/rules/no-implicit-any-catch.ts84.61% <84.61%> (ø)

Copy link
Member

@bradzacherbradzacher left a 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!

@bradzacherbradzacher added the enhancement: new plugin ruleNew rule request for eslint-plugin labelJun 11, 2020
@bradzacherbradzacher added the awaiting responseIssues waiting for a reply from the OP or another party labelJun 19, 2020
@bradzacherbradzacher removed the awaiting responseIssues waiting for a reply from the OP or another party labelJun 22, 2020
@tom-sherman
Copy link

tom-sherman commentedJul 2, 2020
edited
Loading

Can we have an option on this that enforcesunknown as the argument type in this PR? Or should that be discussed in a seperate issue?

I ideally wantcatch (e) andcatch (e: any) to be errors.

WORMSS, felixfbecker, sindresorhus, albertms10, cyrilgandon, and danielnixon reacted with thumbs up emoji

@bradzacher
Copy link
Member

bradzacher commentedJul 2, 2020
edited
Loading

Can we have an option on this that enforcesunknown as the argument type in this PR? Or should that be discussed in a seperate issue?

@tom-sherman, doesn't this PR already cover that?
https://github.com/typescript-eslint/typescript-eslint/pull/2202/files#diff-edf249e9f9f8af86a2cf0ed9bb7c9a3dR42-R48

@phiresky
Copy link
ContributorAuthor

It does cover that, but I've defaulted it to false since I think you'd usually want to use theno-explicit-any rule for that since it covers all of those cases.

@tom-sherman
Copy link

@bradzacher

doesn't this PR already cover that?

You're right, I missed that part - nice!

@bradzacher
Copy link
Member

I made a few updates to fix the CI, but for some reason github isn't picking up the changes.
I committed to your master branch which this PR is tracking - so the changes are there, but unsure why GH isn't adding them to the PR.

Feel free to take a look and merge master into your branch as well.

@WORMSS
Copy link

I committed to your master branch which this PR is tracking

You were able to push to a different users master branch?

@phiresky
Copy link
ContributorAuthor

phiresky commentedJul 13, 2020
edited
Loading

I committed to your master branch which this PR is tracking - so the changes are there,

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.

@phiresky
Copy link
ContributorAuthor

Never mind, I checked theAllow edits by maintainers checkbox when I created the PR. And github picking it up is probably just because it was down (again) earlier today.

@bradzacher
Copy link
Member

You were able to push to a different users master branch?

@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.

image

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:

  • removes agency and ownership from the contributor
  • is a pain as their local branch will be out of sync with their remote

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:

  • If I have a minor one-line change (i.e. a documentation change), that's not worth RCing and bothering the contributor with.
  • If I want to get something in for a release, I sometimes just make changes myself because I don't know when , and comment with what I did and why.

probably just because it was down (again) earlier today

Yeah, it looks like it was just a problem with github. Seems to be working now.

@bradzacher
Copy link
Member

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 hownull types are represented in addition to the other changes.

Before, the TS parser just outputNullKeyword, but now it outputsLiteralType > NullKeyword, which is a breaking change that we need to "undo".

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
Copy link
Member

@bradzacherbradzacher left a 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 ourall config, so I don't want to force consumers of that to upgrade to abeta TS version.

@bradzacherbradzacher added the DO NOT MERGEPRs which should not be merged yet labelJul 20, 2020
@bradzacherbradzacher added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelAug 7, 2020
@cyrilgandon
Copy link

What about thrown Promises, should it be included in this rule too?

async function foo() {}foo().catch((err) => console.error(err));            ---- Disallow usage of the implicit `any` type in catch clauses

@bradzacherbradzacher removed the DO NOT MERGEPRs which should not be merged yet labelAug 21, 2020
@bradzacher
Copy link
Member

No - thatcatch is a function call - so it is handled by things like theno-unsafe-* ruleset.
This rule is specifically about enforcing usage of the new TS4.0 synax.

cyrilgandon reacted with thumbs up emoji

@bradzacherbradzacher changed the titlefeat(eslint-plugin): add no-implicit-any-catch rulefeat(eslint-plugin): addno-implicit-any-catch ruleAug 21, 2020
@bradzacherbradzacher merged commitfde89d4 intotypescript-eslint:masterAug 21, 2020
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsSep 21, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@glen-84glen-84glen-84 left review comments

@WORMSSWORMSSWORMSS requested changes

@bradzacherbradzacherbradzacher approved these changes

Assignees
No one assigned
Labels
1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we mergeenhancement: new plugin ruleNew rule request for eslint-plugin
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@phiresky@tom-sherman@bradzacher@WORMSS@cyrilgandon@glen-84

[8]ページ先頭

©2009-2025 Movatter.jp