Skip to content

Bug: [promise-function-async] Invalid fixer for method named catch #5729

Closed
@SimenB

Description

@SimenB

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=4.8.3&sourceType=module&code=KYDwDg9gTgLgBAE2AMwIYFcA28DGnUDOBcACgMKoB2Ow+ARpsADwAqAfHAJYC2Yj3wSjGIkoEbpwLAAMpwDWzdnADeAKDhwwUTgDdUMYHCjBUCCJUwBPOAH0t4ycABcpMRKms2AblXq4OcwIYKHQcGGgACgBKFT8NGAALSQA6OzdHOABeOEpgAHdXBykI6KyOZTgAXyifDUrfeITBVgAlYAIsGABGLLgWABo+to7sACZe3J1gKDYIuLhzADEsZE5MRgQAfid5jQAfOBK9THRnPpjMjhZhzp6D0SKZeUUb7C62KN24A-RKJFXcggvgdKFhMP15uY2gArYBhYBbHYaZHfQ4RYyEcwuX5ySgQPKUC5XV4wcb3dJSWQKVrtTqjD7AuC-f6cQGM0HrCEaKIuB7uF60t6o66C0nlebGGDoKCUOCJFJpR7JRKCCJLFZrDaDKHAWHwhA1Pz1Pw4fQ4BI0kYwWaQygwuEGRGMkoYghYpmUXH4wllIai1F8xxUgVWhko-Yells8Oojngvw8wr81jCknilGS6Wy+UEVL2fnJU0wc1qu26h0Iw11VSVIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6AewFtLlFaAM1hMy+Spya0AhskKj0URNC7RI4MAF8QmoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

export default class PCancelable<T> implements PromiseLike<T> {
  private readonly _promise: Promise<T>;

  constructor() {
    this._promise = new Promise(() => { });
  }

  then<TResult1 = T, TResult2 = never>(
    onFulfilled?:
      | ((value: T) => TResult1 | PromiseLike<TResult1>)
      | undefined
      | null,
    onRejected?:
      | ((reason: unknown) => TResult2 | PromiseLike<TResult2>)
      | undefined
      | null,
  ): Promise<TResult1 | TResult2> {
    return this._promise.then(onFulfilled, onRejected);
  }

  catch<TResult>(
    onRejected?:
      | ((reason: unknown) => TResult | PromiseLike<TResult>)
      | undefined
      | null,
  ): Promise<T | TResult> {
    return this._promise.catch(onRejected);
  }
}

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/promise-function-async": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

export default class PCancelable<T> implements PromiseLike<T> {
  private readonly _promise: Promise<T>;

  constructor() {
    this._promise = new Promise(() => {});
  }

  async then<TResult1 = T, TResult2 = never>(
    onFulfilled?:
      | ((value: T) => TResult1 | PromiseLike<TResult1>)
      | undefined
      | null,
    onRejected?:
      | ((reason: unknown) => TResult2 | PromiseLike<TResult2>)
      | undefined
      | null,
  ): Promise<TResult1 | TResult2> {
    return this._promise.then(onFulfilled, onRejected);
  }

  async catch<TResult>(
    onRejected?:
      | ((reason: unknown) => TResult | PromiseLike<TResult>)
      | undefined
      | null,
  ): Promise<T | TResult> {
    return this._promise.catch(onRejected);
  }
}

Actual Result

Instead of async catch<TResult>(, the fixer produces catch async <TResult>( which is invalid syntax.

Additional Info

No response

Versions

package version
@typescript-eslint/eslint-plugin 5.38.1
@typescript-eslint/parser 5.38.1
TypeScript 4.8.3
ESLint 8.15.0
node web

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions