Skip to content

Enhancement: [prefer-optional-chain] handle cases where the first logical(s) are unrelated to the proceeding logicals #6332

@dimaMachina

Description

@dimaMachina

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/prefer-optional-chain

Description

here is totally safe to refactor as I mention in Pass

Fail

if (!baz || !foo || !foo.bar) {
  
}

Pass

if (!baz || !foo?.bar) {
  
}

Additional Info

https://typescript-eslint.io/play/#ts=4.9.3&sourceType=module&code=JYMwBAFAhARghgLzAH2WKID2mVo9gOngCcBKMAbwCgwwqBfIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WloHsalfkwCG8WmQAWo5uki9o-aJHBgAviHVA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: 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