Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

[New Rule] add noAsyncWithoutAwait rule #3945

Merged
merged 15 commits into from
Jun 16, 2019

Conversation

eranshabi
Copy link
Contributor

@eranshabi eranshabi commented Jun 6, 2018

PR checklist

Overview of change:

Add a new rule ("noAsyncWithoutAwait"). The rule makes sure that a function will not be an async function, unless it has an await;

Is there anything you'd like reviewers to focus on?

CHANGELOG.md entry:

[new-rule] no-async-without-await

src/rules/code-examples/noAsyncWithoutAwait.examples.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/runner.ts Outdated Show resolved Hide resolved
@giladgray
Copy link

@eranshabi please merge latest master, i believe we've resolved the test failures.

src/runner.ts Outdated Show resolved Hide resolved
@eranshabi
Copy link
Contributor Author

eranshabi commented Jul 6, 2018

I fixed the rule's support of implicit promise return statements.
Thank you for your feedback.
@giladgray is there anything else needed for this PR to be merged?

@eranshabi
Copy link
Contributor Author

All builds are green now

@eranshabi
Copy link
Contributor Author

@giladgray @jkillian @suchanlee anything else needed for merge?
thanks

@adidahiya adidahiya closed this Aug 16, 2018
@adidahiya adidahiya reopened this Aug 16, 2018
@bjornstar
Copy link
Contributor

We'd really like to add this rule to our project, is there any chance someone can review this?

Copy link
Contributor

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

Functionality looks good! Waiting on a few touchups of the implementation details and some more rationale details.

optionExamples: [true],
options: null,
optionsDescription: "Not configurable.",
rationale: "Cleaner code, can possibly reduce transpiled output",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please explain this in more detail. Someone reading this rule's page on palantir.github.io would leave with more questions than they started with.

src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
if (this.isAsyncFunction(node)
&& !this.functionBlockHasAwait(node.body as ts.Node)
&& !this.functionBlockHasReturn(node.body as ts.Node)
&& !this.isShortArrowReturn(node)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Performance nit: please move isShortArrowReturn first. Seems like we could be slightly faster by performing that very fast check before doing deeper searches.

@eranshabi
Copy link
Contributor Author

Thanks for the feedback @JoshuaKGoldberg, fixed by latest commit.

@eranshabi
Copy link
Contributor Author

Hey @JoshuaKGoldberg is anything else needed before merging?

Copy link
Contributor

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

Took a deeper look - some things to fix up.

So sorry for the delay @eranshabi! I had a pending review started then dropped it ☹

src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
@eranshabi
Copy link
Contributor Author

Thanks for the review @JoshuaKGoldberg, I pushed a fix for everything.

@eranshabi
Copy link
Contributor Author

anything else needed for merge? @JoshuaKGoldberg @giladgray

src/rules/code-examples/noAsyncWithoutAwait.examples.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
src/rules/noAsyncWithoutAwaitRule.ts Outdated Show resolved Hide resolved
@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Jan 2, 2019

@eranshabi I took another structural look and posted some feedback. Once all mine are addressed I think we should still wait for a palantirtech maintainer to take a look, since this is a slightly tricky rule It's been long enough that I feel comfortable merging this in.

Edit: it's been a bit since the original review so apologies in advance if some of the feedback is duplicate 😊

@JoshuaKGoldberg
Copy link
Contributor

All right, I cleaned up the merge conflicts and pending PR comments, then refactored this to be a walker function instead of the deprecated class-based approach. It's good to go!

FYI @eranshabi - this'll be in the next TSLint release. Thanks so much for sending this PR in... about a year ago! Sorry it took so long to merge. 😄😢

@JoshuaKGoldberg JoshuaKGoldberg merged commit 0807692 into palantir:master Jun 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Rule: no async without await
5 participants