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

Rule await-promise: make Promise implementation configurable #2661

Closed
darxriggs opened this issue May 1, 2017 · 2 comments
Closed

Rule await-promise: make Promise implementation configurable #2661

darxriggs opened this issue May 1, 2017 · 2 comments

Comments

@darxriggs
Copy link
Contributor

Feature Request

  • TSLint version: 5.1.0
  • TypeScript version: 2.3.2
  • Running TSLint via: CLI

TypeScript code being linted

import * as Bluebird from 'bluebird';

function functionReturningThenable(): Bluebird.Thenable<string> {
    return Bluebird.resolve('some data');
}

async function main(): Promise<void> {
    const data = await functionReturningThenable();
    console.log(data);
}

with tslint.json configuration:

{
  "rules": {
    "await-promise": true
  }
}

Actual behavior

(await-promise) src/test.ts[8, 18]: 'await' of non-Promise.

Expected behavior

No error should be reported.

There are multiple Promise implementations and interfaces out there (JQueryPromise, Q.Promise, Thenable, etc.). Also see Promises/A+, Therefore the rule should be configurable like no-floating-promises already is.

@darxriggs
Copy link
Contributor Author

I'd like to create PR for this but I've seen #2631 ("no-floating-promises: rewrite as walker function").

So the question is if this rule should use applyWithWalker or applyWithFunction and why?

@ajafff
Copy link
Contributor

ajafff commented May 2, 2017

@darxriggs we want to move away from RuleWalker and therefore ProgramAwareRuleWalker and eventually deprecate them. await-promise has not been refactored to use either AbstractWalker or applyWithFunction. #2631 would be a good start.

Which one you choose is up to you. For simple rules it's preferred to use a function. When you find yourself in the need to add several closures to the walker function, you should consider using AbstractWalker to avoid the repeated closure allocation.
For more information about the concepts, there is some documentation at https://palantir.github.io/tslint/develop/custom-rules/walker-design.html

darxriggs added a commit to darxriggs/tslint that referenced this issue May 7, 2017
darxriggs added a commit to darxriggs/tslint that referenced this issue May 7, 2017
darxriggs added a commit to darxriggs/tslint that referenced this issue May 7, 2017
darxriggs added a commit to darxriggs/tslint that referenced this issue May 7, 2017
darxriggs added a commit to darxriggs/tslint that referenced this issue May 8, 2017
darxriggs added a commit to darxriggs/tslint that referenced this issue May 8, 2017
darxriggs added a commit to darxriggs/tslint that referenced this issue May 15, 2017
darxriggs added a commit to darxriggs/tslint that referenced this issue May 15, 2017
@nchen63 nchen63 closed this as completed May 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants