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

await-promise: check for-await-of #3297

Merged
merged 6 commits into from Oct 20, 2017
Merged

await-promise: check for-await-of #3297

merged 6 commits into from Oct 20, 2017

Conversation

ajafff
Copy link
Contributor

@ajafff ajafff commented Oct 7, 2017

PR checklist

Overview of change:

[enhancement] await-promise enforces that for-await-of is only used with AsyncIterableIterator
Fixes: #3232

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

Depends on: #3296

CHANGELOG.md entry:

[bugfix] `--test` works correctly with any `compilerOptions.target`
[enhancement] `await-promise` enforces that `for-await-of` is only used with `AsyncIterableIterator`
Fixes: #3232

Depends on: #3296
Copy link
Contributor

@adidahiya adidahiya left a comment

Choose a reason for hiding this comment

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

minor comments. let's get this in 5.8.0

function isPromiseType(type: ts.Type): boolean {
const { target } = type as ts.TypeReference;
return target !== undefined && target.symbol !== undefined && promiseTypes.has(target.symbol.name);
function containsType(type: ts.Type, predicate: (name: string) => boolean): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like a utility we might want in language/utils.ts, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. We also use a similar function in return-undefined and probably in other rules, too.
We need to find a better abstraction than the one used here to make it work for other cases. Will do that in a follow-up PR.

@@ -42,6 +42,7 @@ export class Rule extends Lint.Rules.TypedRule {
/* tslint:enable:object-literal-sort-keys */

public static FAILURE_STRING = "'await' of non-Promise.";
public static FAILURE_FOR_AWAIT_OF = "'for-await-of' of non-AsyncIterable.";
Copy link
Contributor

Choose a reason for hiding this comment

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

I realized both of these error messages are a bit too terse -- how about

  • "Invalid 'await' of a non-Promise value"
  • "Invalid 'for-await-of' of a non-AsyncIterable value"

@adidahiya adidahiya merged commit 3881ddc into palantir:master Oct 20, 2017
HyphnKnight pushed a commit to HyphnKnight/tslint that referenced this pull request Apr 9, 2018
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.

await-promise: misses check 'for await (... of ...)'
2 participants