Skip to content

Enhancement: [no-unnecessary-condition] Option to only enable 'optional chain' related checks #11518

@reteps

Description

@reteps

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/no-unnecessary-condition/#options

Description

Our project gets a lot of false positives related to Unnecessary conditional due to incomplete types in our project. It would be great if we could enable only the "Unnecessary optional chain" errors to aid us in incremental migration.

Fail

This should still flag as `Unnecessary optional chain on a non-nullish value.`


    const option = courseSelect.selectedOptions[0];

    if (option) {
      copyForm.action = option?.dataset.copyUrl ?? '';

Pass

This should still be allowed (previously: ``Unnecessary conditional, comparison is always true, since `"expire" === "expire"` is true.``):


    if (action === 'set_total') {
      explanation =
        'Updating the total time limit will set the given amount of time for the assessment based on when the assessment was started.';
    } else if (action === 'expire') {
      explanation =
        'This will expire the time limit and students will be unable to submit any further answers.';
    }

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting responseIssues waiting for a reply from the OP or another partyenhancement: 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