Skip to content

Bug: [prefer-nullish-coalescing] "inside" comments are removed while fixing #10994

Closed as not planned
@OlivierZal

Description

@OlivierZal

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=5.7.2&fileType=.tsx&code=CYUwxgNghgTiAEEQBd5QFzwM7JgSwDsBzeAH3gIFcIIz5KDQAzQkYAbgFgAoUSWBElQAjTDnzE6VGnQbNWHHjyjwA9ACo08davgBCALwG1m4dt1yQLAmxPww5%2BADInd4I5Ub4CHfqN2mR2laLxIdHnh4AH47AAsPOzxzCPhMLwArR2EgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WlqYSNkAC1pkA9gEMkyMswDm6KL2jjokcGAC%2BILUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

declare let a: string | null | undefined;
declare let b: string | null | undefined;

a /* a */ !== /* b */ undefined /* c */ && /* d */ a /* e */ !== /* f */ null /* g */
  ? /* h */ a /* i */
  : /* j */ b

ESLint Config

{
  "rules": {
    "@typescript-eslint/prefer-nullish-coalescing": "error"
  }
}

tsconfig

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

Expected Result

"Inside" comments are kept:

declare let a: string | null | undefined;
declare let b: string | null | undefined;

a /* a */ /* b */ /* c */ /* d */ /* e */ /* f* / /* g */ /* h */ /* i */ ?? /* j */ b

Actual Result

"Inside" comments are lost:

declare let a: string | null | undefined;
declare let b: string | null | undefined;

a ?? b

Additional Info

#10861 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions