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): [await-thenable] check for-await loop iteree#10008

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

Conversation

kirkwaiblinger
Copy link
Member

@kirkwaiblingerkirkwaiblinger commentedSep 17, 2024
edited
Loading

PR Checklist

Overview

Just ask the type checker if aSymbol.asyncIterator is present, ezpz. Add tests and docs (less ezpz).

@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 onhttps://opencollective.com/typescript-eslint.

@nx-cloudNx Cloud
Copy link

nx-cloudbot commentedSep 17, 2024
edited
Loading

☁️ Nx Cloud Report

CI is running/has finished running commands for commit7cd8ba7. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 28 targets

Sent with 💌 fromNxCloud.

## Async Iteration (`for await...of` Loops)

This rule also inspects [`for await...of` statements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of), which are designed for iterating over async-iterable objects.
If the value being iterated over is not async-iterable, an ordinary `for...of` statement is preferable, even if the value is an iterable of Thenables.
Copy link
Member

Choose a reason for hiding this comment

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

This is debatable. Banning iterables of thenables should be an option.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Eh, kind of... in any case, I was going off of#8858 (comment). It's easy enough to add an option to allow iterables of thenables, though I'm -0.5 on doing so.

Copy link
Member

Choose a reason for hiding this comment

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

In lieu of an option, can we add more motivation to the docs (as what I said in that comment)?

kirkwaiblinger reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Good point! Made some changes around this 👍

@codecovCodecov
Copy link

codecovbot commentedSep 17, 2024
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.03%. Comparing base(4d31ebe) to head(7cd8ba7).
Report is 57 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@##             main   #10008      +/-   ##==========================================+ Coverage   86.00%   86.03%   +0.02%==========================================  Files         425      428       +3       Lines       14810    14930     +120       Branches     4308     4329      +21     ==========================================+ Hits        12738    12845     +107- Misses       1723     1741      +18+ Partials      349      344       -5
FlagCoverage Δ
unittest86.03% <100.00%> (+0.02%)⬆️

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

Files with missing linesCoverage Δ
packages/eslint-plugin/src/rules/await-thenable.ts100.00% <100.00%> (ø)

... and21 files with indirect coverage changes

@netlifyNetlify
Copy link

netlifybot commentedSep 17, 2024

Deploy Preview fortypescript-eslint failed.

NameLink
🔨 Latest commit353bb30
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/66e9fc172d3e3c0008abbb17

@netlifyNetlify
Copy link

netlifybot commentedSep 17, 2024
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit7cd8ba7
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/66facd2e21b039000844ab8d
😎 Deploy Previewhttps://deploy-preview-10008--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: 100 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (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 yourNetlify site configuration.

// This suggestion causes broken code for sync iterables of promises, since
// the loop variable will not be awaited.
//
// Ideally, if the iterable yields promises, we would offer a suggestion to
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

bleh - I guess this isn't always a good idea, particularly with possibly infinite iterables. But, then again, why would you have an infinite sync iterable of promises? Thinking out loud.

@kirkwaiblingerkirkwaiblinger added the enhancementNew feature or request labelSep 18, 2024
context.report({
loc: getForStatementHeadLoc(context.sourceCode, node),
messageId: 'forAwaitOfNonThenable',
suggest: [
Copy link
Member

Choose a reason for hiding this comment

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

Can we only offer this suggestion if the iterator result is not thenable?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I don't think so because we'd needgetIterationTypesOfIterable() orgetIteratedTypeOrElementType or similar from TS none of which is exposed on thechecker.

If we check arrays and tuples specifically, i.e. known iterables, this is silly since

for(constpromisedValueofawaitPromise.all(promises)){}

is a much better suggestion in those cases (sinceawaiting in the loop is generally problematic for exception handling given a non-lazy array of promises)

Whereas with lazy sync-iterables of promises, which I don't know if we can detect, it may be better to do

for(constpromiseofyieldPromises()){constpromisedValue=awaitpromise;}

I guess the only thing that's unambiguous here is that if you have an array or tuple of non-thenables, this suggestion is good. Maybe that's the only situation where we give a suggestion?

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

I am wholly satisfied with this, except for the one line of missing test coverage. Then we're good to go IMO! 🚀

kirkwaiblinger reacted with thumbs up emoji
@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelSep 30, 2024
@github-actionsgithub-actionsbot removed the awaiting responseIssues waiting for a reply from the OP or another party labelSep 30, 2024
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

🚢

@JoshuaKGoldbergJoshuaKGoldberg merged commitb121bd9 intotypescript-eslint:mainSep 30, 2024
60 of 61 checks passed
@kirkwaiblingerkirkwaiblinger deleted the for-await-thenable branchSeptember 30, 2024 16:59
@phaux
Copy link
Contributor

wrong rule in title lol

kirkwaiblinger reacted with eyes emoji

@kirkwaiblinger
Copy link
MemberAuthor

wrong rule in title lol

smh 😞. Changing the title and release notes, thanks for pointing this out!

@kirkwaiblingerkirkwaiblinger changed the titlefeat(eslint-plugin): [return-await] check for-await loop itereefeat(eslint-plugin): [await-thenable] check for-await loop itereeOct 2, 2024
@haines
Copy link
Contributor

haines commentedOct 7, 2024
edited
Loading

I think this can result in false positives:#10111

Edit: sorry, I see you're already aware of this from#10080

@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsOct 15, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

@Josh-CenaJosh-CenaAwaiting requested review from Josh-Cena

Assignees
No one assigned
Labels
enhancementNew feature or request
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Enhancement: [await-thenable] should check thatfor-await loop is used on an async iterable
5 participants
@kirkwaiblinger@phaux@haines@JoshuaKGoldberg@Josh-Cena

[8]ページ先頭

©2009-2025 Movatter.jp