typescript:S4822 yield keyword should be accepted

I’m using sonarlint on vscode and in a function generator :

 @(task(function* (this: CryptoCurrenciesDashboardExchangeAccountController, uuid: string, file: File) {
    const exchangeAccountfile = this.store.createRecord('crypto-currency-exchange-account-file');
    exchangeAccountfile.exchangeAccount = this.exchangeAccount;
    const extension = '.csv';
    const originalName = file.name;
    const nameWithoutExtension = originalName.substring(0, originalName.lastIndexOf(extension));
    exchangeAccountfile.name = nameWithoutExtension
      .substring(0, Math.min(nameWithoutExtension.length, 252))
    exchangeAccountfile.type = ExchangeAccountFileType.FUNDINGS;
    exchangeAccountfile.uuid = uuid;
    try {
      yield exchangeAccountfile.save();
    } catch (e) {
      throw e;
  importTransactionsFile!: Task;

exchangeAccountfile.save() returns a promise.

sonarlint says try is not good “Consider using ‘await’ for the promise inside this ‘try’ or replace it with ‘Promise.prototype.catch(…)’ usage.sonarlint(typescript:S4822)”

but in function generator, yield is equivalent to await.


We have faced with the same problem, too. Any news on that?

Thanks for the reporting!

Issue is created Consider `yield` in S4822 (no-try-promise) · Issue #2683 · SonarSource/SonarJS · GitHub

Better late than never :grimacing: